diff --git a/Framework/CMakeLists.txt b/Framework/CMakeLists.txt index ae5406b1582030dfa13bb448f53c1bae4e350a06..57cdd849235fbc73af01491ec9192df9be687b8a 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 1d9f2eac43b2cf79d42d451b1676e1c71549ba7d..8698a20e4e4cbd59a6310c781fbf66224f0ede42 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 0000000000000000000000000000000000000000..622c68e4aaf4a452a8b19ba75a9b1dba2662bb11 --- /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; +}