diff --git a/Log.cpp b/Log.cpp index b4e7ee34..10bf42ad 100644 --- a/Log.cpp +++ b/Log.cpp @@ -3,9 +3,18 @@ Log * g_Log = nullptr; +static const char * g_LogLevelStr[eNumLogLevels] = +{ + "error", // eLogError + "warn", // eLogWarning + "info", // eLogInfo + "debug" // eLogDebug +}; + void LogMsg::Process() { - output << boost::posix_time::second_clock::local_time().time_of_day () << " - "; + output << boost::posix_time::second_clock::local_time().time_of_day () << + "/" << g_LogLevelStr[level] << " - "; output << s.str(); } diff --git a/Log.h b/Log.h index 9195ca03..41ab0ea2 100644 --- a/Log.h +++ b/Log.h @@ -8,12 +8,22 @@ #include #include "Queue.h" +enum LogLevel +{ + eLogError = 0, + eLogWarning, + eLogInfo, + eLogDebug, + eNumLogLevels +}; + struct LogMsg { std::stringstream s; std::ostream& output; + LogLevel level; - LogMsg (std::ostream& o = std::cout): output (o) {}; + LogMsg (std::ostream& o = std::cout, LogLevel l = eLogInfo): output (o), level (l) {}; void Process(); }; @@ -72,9 +82,10 @@ void LogPrint (std::stringstream& s, TValue arg, TArgs... args) } template -void LogPrint (TArgs... args) +void LogPrint (LogLevel level, TArgs... args) { - LogMsg * msg = (g_Log && g_Log->GetLogFile ()) ? new LogMsg (*g_Log->GetLogFile ()) : new LogMsg (); + LogMsg * msg = (g_Log && g_Log->GetLogFile ()) ? new LogMsg (*g_Log->GetLogFile (), level) : + new LogMsg (std::cout, level); LogPrint (msg->s, args...); msg->s << std::endl; if (g_Log) @@ -84,6 +95,12 @@ void LogPrint (TArgs... args) msg->Process (); delete msg; } +} + +template +void LogPrint (TArgs... args) +{ + LogPrint (eLogInfo, args...); } #endif