2013-12-10 13:00:13 +00:00
|
|
|
#include "Log.h"
|
2014-08-17 05:35:09 +00:00
|
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
2013-12-10 13:00:13 +00:00
|
|
|
|
2014-07-02 17:48:45 +00:00
|
|
|
Log * g_Log = nullptr;
|
2014-04-22 22:10:21 +00:00
|
|
|
|
2014-10-28 20:36:17 +00:00
|
|
|
static const char * g_LogLevelStr[eNumLogLevels] =
|
|
|
|
{
|
|
|
|
"error", // eLogError
|
|
|
|
"warn", // eLogWarning
|
|
|
|
"info", // eLogInfo
|
|
|
|
"debug" // eLogDebug
|
|
|
|
};
|
|
|
|
|
2014-04-22 22:10:21 +00:00
|
|
|
void LogMsg::Process()
|
|
|
|
{
|
2014-10-28 20:36:17 +00:00
|
|
|
output << boost::posix_time::second_clock::local_time().time_of_day () <<
|
|
|
|
"/" << g_LogLevelStr[level] << " - ";
|
2014-04-22 22:10:21 +00:00
|
|
|
output << s.str();
|
2014-04-23 16:49:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Log::Flush ()
|
|
|
|
{
|
2014-12-08 21:27:10 +00:00
|
|
|
if (m_LogStream)
|
|
|
|
m_LogStream->flush();
|
2014-04-23 16:49:02 +00:00
|
|
|
}
|
|
|
|
|
2014-04-24 15:10:46 +00:00
|
|
|
void Log::SetLogFile (const std::string& fullFilePath)
|
|
|
|
{
|
2014-12-08 21:27:10 +00:00
|
|
|
auto logFile = new std::ofstream (fullFilePath, std::ofstream::out | std::ofstream::binary | std::ofstream::trunc);
|
|
|
|
if (logFile->is_open ())
|
|
|
|
{
|
|
|
|
SetLogStream (logFile);
|
2014-04-24 15:10:46 +00:00
|
|
|
LogPrint("Logging to file ", fullFilePath, " enabled.");
|
2014-12-08 21:27:10 +00:00
|
|
|
}
|
2014-04-24 15:10:46 +00:00
|
|
|
else
|
2014-12-08 21:27:10 +00:00
|
|
|
delete logFile;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Log::SetLogStream (std::ostream * logStream)
|
|
|
|
{
|
|
|
|
if (m_LogStream) delete m_LogStream;
|
|
|
|
m_LogStream = logStream;
|
2014-04-24 15:10:46 +00:00
|
|
|
}
|