66#include < string>
77using namespace std ;
88
9+ struct OUT
10+ {
11+ public:
12+ static const string black;
13+ static const string red;
14+ static const string green;
15+ static const string yellow;
16+ static const string blue;
17+ static const string magenta;
18+ static const string cyan;
19+ static const string white;
20+
21+ static const string bold;
22+ static const string underline;
23+
24+ static const string reset;
25+ };
26+
27+ const string OUT::black = " \033 [30m" ;
28+ const string OUT::red = " \033 [31m" ;
29+ const string OUT::green = " \033 [32m" ;
30+ const string OUT::yellow = " \033 [33m" ;
31+ const string OUT::blue = " \033 [34m" ;
32+ const string OUT::magenta = " \033 [35m" ;
33+ const string OUT::cyan = " \033 [36m" ;
34+ const string OUT::white = " \033 [37m" ;
35+ const string OUT::bold = " \033 [1m" ;
36+ const string OUT::underline = " \033 [4m" ;
37+ const string OUT::reset = " \033 [0m" ;
38+
39+
940#include " config.hpp"
1041
1142// enable easy logging of STL containers
@@ -20,6 +51,10 @@ using namespace std;
2051 #define _ELPP_STACKTRACE_ON_CRASH
2152#endif
2253
54+ #ifdef PFASST_NO_LOGGING
55+ #define _ELPP_DISABLE_LOGS
56+ #endif
57+
2358#include < easylogging++.h>
2459
2560#ifndef PFASST_LOGGER_INITIALIZED
@@ -38,42 +73,54 @@ using namespace std;
3873 #define PFASST_LOGGER_INITIALIZED
3974#endif
4075
41- #ifndef PFASST_LOGGER_DEFAULT_GLOBAL_FORMAT
42- // ! format for the default global logger
43- #define PFASST_LOGGER_DEFAULT_GLOBAL_FORMAT " [%level] %msg "
76+ #ifndef PFASST_LOGGER_DEFAULT_GLOBAL_MILLISECOND_WIDTH
77+ // ! precision of milliseconds to be printed
78+ #define PFASST_LOGGER_DEFAULT_GLOBAL_MILLISECOND_WIDTH " 4 "
4479#endif
4580
46- #ifndef PFASST_LOGGER_DEFAULT_GLOBAL_TOFILE
47- // ! whether to log to file by default
48- #define PFASST_LOGGER_DEFAULT_GLOBAL_TOFILE " false"
49- #endif
50- #ifndef PFASST_LOGGER_DEFAULT_GLOBAL_TOSTDOUT
51- // ! whether to log to stdout by default
52- #define PFASST_LOGGER_DEFAULT_GLOBAL_TOSTDOUT " true"
53- #endif
54-
55- #ifndef PFASST_LOGGER_DEFAULT_DEBUG_FORMAT
56- // ! format for the default global debug logger
57- #define PFASST_LOGGER_DEFAULT_DEBUG_FORMAT " [%datetime{%Y-%M-%d %H:%m:%s,%g}] %level - %fbase:%line - %msg"
58- #endif
5981
6082namespace pfasst
6183{
6284 namespace log
6385 {
64-
6586 /* *
6687 * sets default configuration for default loggers
6788 */
6889 static void load_default_config ()
6990 {
91+ const string TIMESTAMP = OUT::white + " %datetime{%H:%m:%s,%g}" + OUT::reset + " " ;
92+ const string LEVEL = " [%level]" ;
93+ const string VLEVEL = " [VERB%vlevel]" ;
94+ const string POSITION = " %fbase:%line" ;
95+ const string MESSAGE = " %msg" ;
96+
7097 el::Configurations defaultConf;
7198 defaultConf.setToDefault ();
72- defaultConf.set (el::Level::Global, el::ConfigurationType::Format, PFASST_LOGGER_DEFAULT_GLOBAL_FORMAT);
73- defaultConf.set (el::Level::Global, el::ConfigurationType::ToFile, PFASST_LOGGER_DEFAULT_GLOBAL_TOFILE);
74- defaultConf.set (el::Level::Global, el::ConfigurationType::ToStandardOutput, PFASST_LOGGER_DEFAULT_GLOBAL_TOSTDOUT);
75- defaultConf.set (el::Level::Debug, el::ConfigurationType::Format, PFASST_LOGGER_DEFAULT_DEBUG_FORMAT);
76- el::Loggers::reconfigureLogger (" default" , defaultConf);
99+
100+ defaultConf.setGlobally (el::ConfigurationType::Format, " %msg" );
101+ defaultConf.setGlobally (el::ConfigurationType::ToFile, " false" );
102+ defaultConf.setGlobally (el::ConfigurationType::ToStandardOutput, " true" );
103+ defaultConf.setGlobally (el::ConfigurationType::MillisecondsWidth, PFASST_LOGGER_DEFAULT_GLOBAL_MILLISECOND_WIDTH);
104+
105+ defaultConf.set (el::Level::Info, el::ConfigurationType::Format,
106+ TIMESTAMP + OUT::blue + LEVEL + " " + MESSAGE + OUT::reset);
107+
108+ defaultConf.set (el::Level::Debug, el::ConfigurationType::Format,
109+ TIMESTAMP + LEVEL + " " + POSITION + " " + MESSAGE + OUT::reset);
110+
111+ defaultConf.set (el::Level::Warning, el::ConfigurationType::Format,
112+ TIMESTAMP + OUT::magenta + LEVEL + " " + MESSAGE + OUT::reset);
113+
114+ defaultConf.set (el::Level::Error, el::ConfigurationType::Format,
115+ TIMESTAMP + OUT::red + LEVEL + " " + MESSAGE + OUT::reset);
116+
117+ defaultConf.set (el::Level::Fatal, el::ConfigurationType::Format,
118+ TIMESTAMP + OUT::red + OUT::bold + LEVEL + " " + POSITION + " " + MESSAGE + OUT::reset);
119+
120+ defaultConf.set (el::Level::Verbose, el::ConfigurationType::Format,
121+ TIMESTAMP + OUT::white + VLEVEL + " " + MESSAGE + OUT::reset);
122+
123+ el::Loggers::reconfigureAllLoggers (defaultConf);
77124 }
78125
79126 /* *
@@ -83,9 +130,9 @@ namespace pfasst
83130 *
84131 * - NewLineForContainer
85132 * - LogDetailedCrashReason
133+ * - DisableApplicationAbortOnFatalLog
86134 * - ColoredTerminalOutput
87135 * - MultiLoggerSupport
88- * - HierarchicalLogging
89136 * - AutoSpacing
90137 *
91138 * \see https://github.com/easylogging/easyloggingpp#logging-flags
@@ -94,12 +141,32 @@ namespace pfasst
94141 {
95142 el::Loggers::addFlag (el::LoggingFlag::NewLineForContainer);
96143 el::Loggers::addFlag (el::LoggingFlag::LogDetailedCrashReason);
144+ el::Loggers::addFlag (el::LoggingFlag::DisableApplicationAbortOnFatalLog);
97145 el::Loggers::addFlag (el::LoggingFlag::ColoredTerminalOutput);
98146 el::Loggers::addFlag (el::LoggingFlag::MultiLoggerSupport);
99- el::Loggers::addFlag (el::LoggingFlag::HierarchicalLogging );
147+ el::Loggers::addFlag (el::LoggingFlag::CreateLoggerAutomatically );
100148 el::Loggers::addFlag (el::LoggingFlag::AutoSpacing);
101149 }
102150
151+ #ifdef NDEBUG
152+ static void test_logging_levels () {}
153+ #else
154+ static void test_logging_levels ()
155+ {
156+ cout << " ### Example of different Logging Levels:" << endl;
157+ LOG (INFO) << " info" ;
158+ LOG (DEBUG) << " debug" ;
159+ LOG (WARNING) << " warning" ;
160+ LOG (ERROR) << " error" ;
161+ LOG (FATAL) << " fatal error" ;
162+ LOG (TRACE) << " trace" ;
163+ for (size_t level = 0 ; level <= 9 ; ++level) {
164+ VLOG (level) << " verbose level" << level;
165+ }
166+ cout << " ### End Example Logging Levels" << endl << endl;
167+ }
168+ #endif
169+
103170 /* *
104171 * starts easylogging++ with given arguments and loads configuration
105172 *
@@ -112,8 +179,8 @@ namespace pfasst
112179 static void start_log (int argc, char ** argv)
113180 {
114181 _START_EASYLOGGINGPP (argc, argv);
115- load_default_config ();
116182 set_logging_flags ();
183+ load_default_config ();
117184 }
118185 } // ::pfasst::log
119186} // ::pfasst
0 commit comments