2020#include < iomanip>
2121#include < iostream>
2222
23+ #ifdef O2_MONITORING_WITH_INFOLOGGER
24+ #include < InfoLogger/InfoLogger.hxx>
25+ using namespace AliceO2 ::InfoLogger;
26+ #endif
27+
2328namespace o2
2429{
2530// / ALICE O2 Monitoring system
@@ -52,20 +57,21 @@ class MonLogger
5257 // / Returns Logger instance with current date and given severity
5358 // / \param severity - severity level
5459 // / \return - logger instance
55- static MonLogger& Get (Severity severity = Severity::Debug)
60+ static MonLogger& Get (Severity desiredSeverity = Severity::Debug)
5661 {
5762 static MonLogger loggerInstance;
58- loggerInstance.instanceSeverity (severity );
59- loggerInstance.setDate ();
63+ loggerInstance.setSeverity (desiredSeverity );
64+ loggerInstance.logHeader ();
6065 return loggerInstance;
6166 }
6267
6368 // / Terminates log line
6469 // / return - string with color termination and new line
65- static auto End () -> decltype(" \033 [0m\n " )
66- {
67- return " \033 [0m\n " ;
68- }
70+ #ifdef O2_MONITORING_WITH_INFOLOGGER
71+ static auto End () -> decltype(InfoLogger::endm) { return InfoLogger::endm; }
72+ #else
73+ static auto End () -> decltype(" \033 [0m\n " ) { return " \033 [0m\n " ; }
74+ #endif
6975
7076 // / Currently set severity
7177 const Severity LogSeverity = Severity::Info;
@@ -75,26 +81,32 @@ class MonLogger
7581 Severity severity;
7682
7783 // / Log stream
78- std::ostream& mStream ;
79-
80- // / Sets cout as a log stream
81- MonLogger (std::ostream& oStream = std::cout) : mStream (oStream)
84+ #ifdef O2_MONITORING_WITH_INFOLOGGER
85+ InfoLogger mStream ;
86+ void logHeader ()
8287 {
88+ InfoLoggerContext context;
89+ context.setField (InfoLoggerContext::FieldName::System, " Monitoring" );
90+ context.setField (InfoLoggerContext::FieldName::Facility, " Library" );
91+ mStream .setContext (context);
8392 }
84-
85- // / Appends current datetime to log stream
86- void setDate ()
93+ # else
94+ std::ostream& mStream = std::cout;
95+ void logHeader ()
8796 {
97+ *this << " \033 [0;" << static_cast <int >(severity) << " m" ;
8898 auto now = std::chrono::system_clock::to_time_t (std::chrono::system_clock::now ());
8999 *this << std::put_time (std::localtime (&now), " %Y-%m-%d %X" ) << " \t " << " Monitoring" << " \t " ;
90100 }
101+ #endif
91102
92- // / Sets log color based on severity
93- // / \param severity - log severity
94- void instanceSeverity (Severity desiredSeverity)
103+ // / Sets cout as a log stream
104+ MonLogger () = default ;
105+
106+ // / Stream severity setter
107+ void setSeverity (Severity desiredSeverity)
95108 {
96109 severity = desiredSeverity;
97- *this << " \033 [0;" << static_cast <int >(severity) << " m" ;
98110 }
99111
100112 // / Delete copy and move constructors
0 commit comments