mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
* Added sync log to streamer. * Fixed ledger closing attempt while syncing. * Added diagnostic contract. * Reset to stage 0 on unreliable votes. * Reduced peer msg age threshold. * Added health tracking. * Weakly-connected detection improvement. * Increased version 0.5.1. * Improved client lib server version check. * Added health logging support to text client. * Added weakly connected status in status response. * Increased max peers limits when serializing. * Local docker cluster manual ip. * Updated vultr script vm region order. * Sync status reporting improvement. * Added milliseconds to logging.
88 lines
3.2 KiB
C++
88 lines
3.2 KiB
C++
#include "pchheader.hpp"
|
|
#include "conf.hpp"
|
|
#include "hplog.hpp"
|
|
|
|
namespace hplog
|
|
{
|
|
class plog_formatter;
|
|
|
|
// Custom formatter adopted from:
|
|
// https://github.com/SergiusTheBest/plog/blob/master/include/plog/Formatters/TxtFormatter.h
|
|
class plog_formatter
|
|
{
|
|
public:
|
|
static plog::util::nstring header()
|
|
{
|
|
return plog::util::nstring();
|
|
}
|
|
|
|
static inline const char *severity_to_string(plog::Severity severity)
|
|
{
|
|
switch (severity)
|
|
{
|
|
case plog::Severity::fatal:
|
|
return "fat";
|
|
case plog::Severity::error:
|
|
return "err";
|
|
case plog::Severity::warning:
|
|
return "wrn";
|
|
case plog::Severity::info:
|
|
return "inf";
|
|
case plog::Severity::debug:
|
|
return "dbg";
|
|
case plog::Severity::verbose:
|
|
return "ver";
|
|
default:
|
|
return "def";
|
|
}
|
|
}
|
|
|
|
static plog::util::nstring format(const plog::Record &record)
|
|
{
|
|
tm t;
|
|
plog::util::localtime_s(&t, &record.getTime().time); // local time
|
|
|
|
plog::util::nostringstream ss;
|
|
ss << t.tm_year + 1900 << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_mon + 1 << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_mday
|
|
<< PLOG_NSTR(" ") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_hour
|
|
<< PLOG_NSTR(":") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_min
|
|
<< PLOG_NSTR(":") << std::setfill(PLOG_NSTR('0')) << std::setw(2) << t.tm_sec
|
|
<< PLOG_NSTR(".") << std::setfill(PLOG_NSTR('0')) << std::setw(3) << record.getTime().millitm // Uncomment for millseconds.
|
|
<< PLOG_NSTR(" ") << PLOG_NSTR("[") << severity_to_string(record.getSeverity())
|
|
<< PLOG_NSTR("][hpc] ") << record.getMessage() << PLOG_NSTR("\n");
|
|
|
|
return ss.str();
|
|
}
|
|
};
|
|
|
|
void init()
|
|
{
|
|
plog::Severity level;
|
|
|
|
if (conf::cfg.log.log_level_type == conf::LOG_SEVERITY::DEBUG)
|
|
level = plog::Severity::debug;
|
|
else if (conf::cfg.log.log_level_type == conf::LOG_SEVERITY::INFO)
|
|
level = plog::Severity::info;
|
|
else if (conf::cfg.log.log_level_type == conf::LOG_SEVERITY::WARN)
|
|
level = plog::Severity::warning;
|
|
else
|
|
level = plog::Severity::error;
|
|
|
|
const std::string trace_file = conf::ctx.log_dir + "/hp.log";
|
|
static plog::RollingFileAppender<plog_formatter> fileAppender(trace_file.c_str(), conf::cfg.log.max_mbytes_per_file * 1024 * 1024, conf::cfg.log.max_file_count);
|
|
static plog::ColorConsoleAppender<plog_formatter> consoleAppender;
|
|
|
|
plog::Logger<0> &logger = plog::init(level);
|
|
|
|
// Take decision to append logger for file / console or both.
|
|
if (conf::cfg.log.loggers.count("console") == 1)
|
|
{
|
|
logger.addAppender(&consoleAppender);
|
|
}
|
|
|
|
if (conf::cfg.log.loggers.count("file") == 1)
|
|
{
|
|
logger.addAppender(&fileAppender);
|
|
}
|
|
}
|
|
} // namespace hplog
|