|
|
@ -13,7 +13,8 @@ static const char * g_LogLevelStr[eNumLogLevels] = |
|
|
|
|
|
|
|
|
|
|
|
void LogMsg::Process() |
|
|
|
void LogMsg::Process() |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto& output = (log && log->GetLogStream ()) ? *log->GetLogStream () : std::cerr; |
|
|
|
auto stream = log ? log->GetLogStream () : nullptr; |
|
|
|
|
|
|
|
auto& output = stream ? *stream : std::cout; |
|
|
|
if (log) |
|
|
|
if (log) |
|
|
|
output << log->GetTimestamp (); |
|
|
|
output << log->GetTimestamp (); |
|
|
|
else |
|
|
|
else |
|
|
@ -45,14 +46,12 @@ void Log::Flush () |
|
|
|
|
|
|
|
|
|
|
|
void Log::SetLogFile (const std::string& fullFilePath) |
|
|
|
void Log::SetLogFile (const std::string& fullFilePath) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto logFile = new std::ofstream (fullFilePath, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc); |
|
|
|
auto logFile = std::make_shared<std::ofstream> (fullFilePath, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc); |
|
|
|
if (logFile->is_open ()) |
|
|
|
if (logFile->is_open ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
SetLogStream (logFile); |
|
|
|
SetLogStream (logFile); |
|
|
|
LogPrint(eLogInfo, "Log: will send messages to ", fullFilePath); |
|
|
|
LogPrint(eLogInfo, "Log: will send messages to ", fullFilePath); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
|
|
|
|
delete logFile; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Log::SetLogLevel (const std::string& level) |
|
|
|
void Log::SetLogLevel (const std::string& level) |
|
|
@ -65,11 +64,10 @@ void Log::SetLogLevel (const std::string& level) |
|
|
|
LogPrint(eLogError, "Log: Unknown loglevel: ", level); |
|
|
|
LogPrint(eLogError, "Log: Unknown loglevel: ", level); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
LogPrint(eLogInfo, "Log: min messages level set to ", level); |
|
|
|
LogPrint(eLogInfo, "Log: min msg level set to ", level); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Log::SetLogStream (std::ostream * logStream) |
|
|
|
void Log::SetLogStream (std::shared_ptr<std::ostream> logStream) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_LogStream) delete m_LogStream; |
|
|
|
|
|
|
|
m_LogStream = logStream; |
|
|
|
m_LogStream = logStream; |
|
|
|
} |
|
|
|
} |
|
|
|