From 7ac1f055cde5c9a7976e2b31674e4645ace20d00 Mon Sep 17 00:00:00 2001
From: ralfulrich <ralf.ulrich@kit.edu>
Date: Mon, 6 Aug 2018 16:15:31 +0200
Subject: [PATCH] added logging...

---
 Framework/CMakeLists.txt |  1 +
 Main/CMakeLists.txt      |  7 +++++--
 Main/logger_example.cc   | 43 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 2 deletions(-)
 create mode 100644 Main/logger_example.cc

diff --git a/Framework/CMakeLists.txt b/Framework/CMakeLists.txt
index ae5406b1..57cdd849 100644
--- a/Framework/CMakeLists.txt
+++ b/Framework/CMakeLists.txt
@@ -1,3 +1,4 @@
 
 add_subdirectory (Units)
 add_subdirectory (Geometry)
+add_subdirectory (Logging)
diff --git a/Main/CMakeLists.txt b/Main/CMakeLists.txt
index 1d9f2eac..8698a20e 100644
--- a/Main/CMakeLists.txt
+++ b/Main/CMakeLists.txt
@@ -1,7 +1,10 @@
 
 
 add_executable (geometry_example geometry_example.cc)
-
 target_link_libraries (geometry_example CORSIKAgeometry CORSIKAunits)
-
 install (TARGETS geometry_example DESTINATION bin)
+
+
+add_executable (logger_example logger_example.cc)
+target_link_libraries (logger_example CORSIKAunits CORSIKAlogging)
+install (TARGETS logger_example DESTINATION bin)
diff --git a/Main/logger_example.cc b/Main/logger_example.cc
new file mode 100644
index 00000000..622c68e4
--- /dev/null
+++ b/Main/logger_example.cc
@@ -0,0 +1,43 @@
+#include <Logging/Logger.h>
+
+#include <string>
+#include <iostream>
+
+#include <boost/format.hpp>
+
+using namespace std;
+
+int
+main()
+{
+  {
+    ofstream logfile("another.log");
+    typedef Sink<ofstream, StdBuffer> SinkFile;
+    SinkFile sink(logfile, StdBuffer(10000));
+    logger<SinkFile, messageconst> info("\033[32m", "info", sink);
+    logger<SinkFile, messageconst> err("\033[31m", "error", sink);
+    //logger<ostream,messageconst,StdBuffer> info(std::cout, StdBuffer(10000));
+    
+    /*
+      Logging& logs = Logging::GetInstance();
+      logs.AddLogger<>("info", info);
+      auto& log_1 = logs.GetLogger("info"); // no so useful, since type of log_1 is std::any
+    */
+    
+    for (int i=0; i<100000; ++i) {
+    LOG(info, "irgendwas"," ", string("and more")," ", boost::format("error: %i message: %s. done."), i, "stupido");
+    LOG(err, "Fehler");
+    }
+  }
+
+  {
+    NoSink off;
+    logger<NoSink, MessageOff> info("", "", off);
+    
+    for (int i=0; i<100000; ++i) {
+      LOG(info, "irgendwas", string("and more"), boost::format("error: %i message: %s. done."), i, "stupido", "a-number:", 8.99, "ENDE" );
+    }
+  }
+  
+  return 0;
+}
-- 
GitLab