mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-23 17:36:37 +02:00
color log messages for warn and error
This commit is contained in:
parent
f32510e10a
commit
f5684eba90
1 changed files with 21 additions and 1 deletions
22
Log.h
22
Log.h
|
@ -40,8 +40,20 @@ enum LogType {
|
||||||
#endif
|
#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 i2p {
|
||||||
namespace log {
|
namespace log {
|
||||||
|
|
||||||
struct LogMsg; /* forward declaration */
|
struct LogMsg; /* forward declaration */
|
||||||
|
|
||||||
class Log
|
class Log
|
||||||
|
@ -177,8 +189,16 @@ void LogPrint (LogLevel level, TArgs... args)
|
||||||
|
|
||||||
// fold message to single string
|
// fold message to single string
|
||||||
std::stringstream ss("");
|
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());
|
auto msg = std::make_shared<i2p::log::LogMsg>(level, std::time(nullptr), ss.str());
|
||||||
msg->tid = std::this_thread::get_id();
|
msg->tid = std::this_thread::get_id();
|
||||||
log.Append(msg);
|
log.Append(msg);
|
||||||
|
|
Loading…
Add table
Reference in a new issue