Files
hpcore/src/hplog.cpp
Savinda Senevirathne 16c5b3fae2 Introducing ledger shards and new ledger syncing logic. (#247)
- The ledgers are stored in a sqlite database in ledger file system.
- Ledgers are organized in shards inside primary folder.
- Raw inputs are saved as shards inside blob folder. No input files are created if neither inputs nor outputs are available.
- Both last primary shard hash and last blob shard hashes are subjected to consensus and necessary sync operations are performed if out of sync.
- Hpfs sync support setting single sync targets from both ends of the list. (Targets set from front are prioritized).
- Contract and ledger syncs and serving are performed independently.
2021-02-18 11:24:05 +05:30

90 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(" ");
ss << 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(" ");
// Uncomment for millseconds.
// << std::setfill(PLOG_NSTR('0')) << std::setw(3) << record.getTime().millitm << PLOG_NSTR(" ");
ss << PLOG_NSTR("[") << severity_to_string(record.getSeverity()) << PLOG_NSTR("][hpc] ");
ss << record.getMessage() << PLOG_NSTR("\n");
return ss.str();
}
};
void init()
{
plog::Severity level;
if (conf::cfg.log.loglevel_type == conf::LOG_SEVERITY::DEBUG)
level = plog::Severity::debug;
else if (conf::cfg.log.loglevel_type == conf::LOG_SEVERITY::INFO)
level = plog::Severity::info;
else if (conf::cfg.log.loglevel_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