Jpp  18.2.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
jlog.cc
Go to the documentation of this file.
1 #include "log.hh"
2 
6 
7 /**
8  * \author cpellegrino
9  */
10 
11 using namespace JPP;
12 
13 class MLSing
14 {
15  MLSing() {}
16  JMessageLoggerThreadSafe m_mlts;
17 
18  public:
19 
20  static MLSing& get()
21  {
22  static MLSing sing;
23 
24  return sing;
25  }
26 
27  void init(JMessageLoggerThreadSafe const& second)
28  {
29  m_mlts = second;
30  }
31 
32  JMessageLoggerThreadSafe& logger()
33  {
34  return m_mlts;
35  }
36 };
37 
38 void initLogger(JMessageLoggerThreadSafe const& second)
39 {
40  MLSing::get().init(second);
41 }
42 
43 void setLogLevel(int level)
44 {
45  // This shall be protected from race conditions with a mutex to avoid UB.
46  // But this very UB won't really produce any problem, hopefully.
47  MLSing::get().logger().setLevel(level);
48 }
49 
51 {
52  if (m_level == cError) {
53  JLOGGER::JErrorStream(MLSing::get().logger()) << m_stream.str();
54  } else if (m_level == cWarning) {
55  JLOGGER::JWarningStream(MLSing::get().logger()) << m_stream.str();
56  } else if (m_level == cNotice) {
57  JLOGGER::JNoticeStream (MLSing::get().logger()) << m_stream.str();
58  } else if (m_level == cStatus) {
59  JLOGGER::JStatusStream (MLSing::get().logger()) << m_stream.str();
60  } else if (m_level == cDebug) {
61  JLOGGER::JDebugStream (MLSing::get().logger()) << m_stream.str();
62  }
63 }
void initLogger(JLOGGER::JMessageLoggerThreadSafe const &second)
Message reporting compatible with STL output stream operations.
MLSing()
Definition: jlog.cc:15
Definition: jlog.cc:13
~Logger()
Logger without Jpp.
Definition: jlog.cc:50
JMessageLoggerThreadSafe & logger()
Definition: jlog.cc:32
Level specific message streamers.
void setLogLevel(int level)
Definition: jlog.cc:43
General purpose message reporting.
void init(JMessageLoggerThreadSafe const &second)
Definition: jlog.cc:27
static MLSing & get()
Definition: jlog.cc:20
void setLevel(const int __level)
Set debug level.
JMessageLoggerThreadSafe m_mlts
Definition: jlog.cc:16