15 #include <json/json.h>
16 #include <json/reader.h>
17 #include <json/writer.h>
18 #include <json/value.h>
35 pthread_mutex_init(&m_mutex, NULL);
38 m_logfile.open (m_path.c_str(), ios::app);
44 pthread_mutex_destroy(&m_mutex);
66 if (m_logLevel <= level) {
68 pthread_mutex_lock(&m_mutex);
70 replace(msg.begin(), msg.end(),
'\n',
' ');
72 cout << microsec_clock::local_time();
74 cout << (int)getpid() <<
" ";
75 cout <<
"[" << toString(level) <<
"] ";
77 pthread_mutex_unlock(&m_mutex);
79 pthread_mutex_lock(&m_mutex);
81 replace(msg.begin(), msg.end(),
'\n',
' ');
83 cerr << microsec_clock::local_time();
85 cerr << (int)getpid() <<
" ";
86 cerr <<
"[" << toString(level) <<
"] ";
88 pthread_mutex_unlock(&m_mutex);
90 pthread_mutex_lock(&m_mutex);
92 replace(msg.begin(), msg.end(),
'\n',
' ');
94 m_logfile << microsec_clock::local_time();
96 m_logfile << (int)getpid() <<
" ";
97 m_logfile <<
"[" << toString(level) <<
"] ";
98 m_logfile << msg << endl;
99 pthread_mutex_unlock(&m_mutex);
108 if (level ==
"debug")
110 else if (level ==
"info")
112 else if (level ==
"warning")
114 else if (level ==
"error")
118 m_logLevel = boost::lexical_cast<
int>(
"info");
119 }
catch (boost::bad_lexical_cast&) {
static WsLogWriter * m_instance
void write(const int &level, const std::string &message)
writes the message to the log file
WsLogWriter()
Constructor.
void readConf()
reads the conf needed to know log path and verbose level
LogWriter, writes logs to file or screen.
std::string get(const std::string §ion, const std::string &id, const std::string &def)
static WsLogWriter * instance()
returns the instance of the WsLogWriter class. If no instance is existing, a new instance will be ret...
static WsGlobalProperties * instance()
std::string toString(int level)
Converts the log level to string.