mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
color log messages for warn and error
This commit is contained in:
parent
f32510e10a
commit
f5684eba90
22
Log.h
22
Log.h
@ -40,8 +40,20 @@ enum LogType {
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifdef _WIN32
|
||||
const char LOG_COLOR_ERROR[] = "";
|
||||
const char LOG_COLOR_WARNING[] = "";
|
||||
const char LOG_COLOR_RESET[] = "";
|
||||
#else
|
||||
const char LOG_COLOR_ERROR[] = "\033[1;31m";
|
||||
const char LOG_COLOR_WARNING[] = "\033[1;33m";
|
||||
const char LOG_COLOR_RESET[] = "\033[0m";
|
||||
#endif
|
||||
|
||||
|
||||
namespace i2p {
|
||||
namespace log {
|
||||
|
||||
struct LogMsg; /* forward declaration */
|
||||
|
||||
class Log
|
||||
@ -177,8 +189,16 @@ void LogPrint (LogLevel level, TArgs... args)
|
||||
|
||||
// fold message to single string
|
||||
std::stringstream ss("");
|
||||
LogPrint (ss, args ...);
|
||||
|
||||
if(level == eLogError) // if log level is ERROR color log message red
|
||||
ss << LOG_COLOR_ERROR;
|
||||
else if (level == eLogWarning) // if log level is WARN color log message yellow
|
||||
ss << LOG_COLOR_WARNING;
|
||||
LogPrint (ss, args ...);
|
||||
|
||||
// reset color
|
||||
ss << LOG_COLOR_RESET;
|
||||
|
||||
auto msg = std::make_shared<i2p::log::LogMsg>(level, std::time(nullptr), ss.str());
|
||||
msg->tid = std::this_thread::get_id();
|
||||
log.Append(msg);
|
||||
|
Loading…
Reference in New Issue
Block a user