|
|
@ -16,6 +16,7 @@ namespace log { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
static const char * g_LogLevelStr[eNumLogLevels] = |
|
|
|
static const char * g_LogLevelStr[eNumLogLevels] = |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
"none", // eLogNone
|
|
|
|
"error", // eLogError
|
|
|
|
"error", // eLogError
|
|
|
|
"warn", // eLogWarn
|
|
|
|
"warn", // eLogWarn
|
|
|
|
"info", // eLogInfo
|
|
|
|
"info", // eLogInfo
|
|
|
@ -46,6 +47,7 @@ namespace log { |
|
|
|
static inline int GetSyslogPrio (enum LogLevel l) { |
|
|
|
static inline int GetSyslogPrio (enum LogLevel l) { |
|
|
|
int priority = LOG_DEBUG; |
|
|
|
int priority = LOG_DEBUG; |
|
|
|
switch (l) { |
|
|
|
switch (l) { |
|
|
|
|
|
|
|
case eLogNone : priority = LOG_CRIT; break; |
|
|
|
case eLogError : priority = LOG_ERR; break; |
|
|
|
case eLogError : priority = LOG_ERR; break; |
|
|
|
case eLogWarning : priority = LOG_WARNING; break; |
|
|
|
case eLogWarning : priority = LOG_WARNING; break; |
|
|
|
case eLogInfo : priority = LOG_INFO; break; |
|
|
|
case eLogInfo : priority = LOG_INFO; break; |
|
|
@ -105,7 +107,8 @@ namespace log { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Log::SetLogLevel (const std::string& level) { |
|
|
|
void Log::SetLogLevel (const std::string& level) { |
|
|
|
if (level == "error") { m_MinLevel = eLogError; } |
|
|
|
if (level == "none") { m_MinLevel = eLogNone; } |
|
|
|
|
|
|
|
else if (level == "error") { m_MinLevel = eLogError; } |
|
|
|
else if (level == "warn") { m_MinLevel = eLogWarning; } |
|
|
|
else if (level == "warn") { m_MinLevel = eLogWarning; } |
|
|
|
else if (level == "info") { m_MinLevel = eLogInfo; } |
|
|
|
else if (level == "info") { m_MinLevel = eLogInfo; } |
|
|
|
else if (level == "debug") { m_MinLevel = eLogDebug; } |
|
|
|
else if (level == "debug") { m_MinLevel = eLogDebug; } |
|
|
@ -181,6 +184,7 @@ namespace log { |
|
|
|
void Log::SendTo (const std::string& path) |
|
|
|
void Log::SendTo (const std::string& path) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_LogStream) m_LogStream = nullptr; // close previous
|
|
|
|
if (m_LogStream) m_LogStream = nullptr; // close previous
|
|
|
|
|
|
|
|
if (m_MinLevel == eLogNone) return; |
|
|
|
auto flags = std::ofstream::out | std::ofstream::app; |
|
|
|
auto flags = std::ofstream::out | std::ofstream::app; |
|
|
|
auto os = std::make_shared<std::ofstream> (path, flags); |
|
|
|
auto os = std::make_shared<std::ofstream> (path, flags); |
|
|
|
if (os->is_open ()) |
|
|
|
if (os->is_open ()) |
|
|
@ -202,6 +206,7 @@ namespace log { |
|
|
|
|
|
|
|
|
|
|
|
#ifndef _WIN32 |
|
|
|
#ifndef _WIN32 |
|
|
|
void Log::SendTo(const char *name, int facility) { |
|
|
|
void Log::SendTo(const char *name, int facility) { |
|
|
|
|
|
|
|
if (m_MinLevel == eLogNone) return; |
|
|
|
m_HasColors = false; |
|
|
|
m_HasColors = false; |
|
|
|
m_Destination = eLogSyslog; |
|
|
|
m_Destination = eLogSyslog; |
|
|
|
m_LogStream = nullptr; |
|
|
|
m_LogStream = nullptr; |
|
|
|