mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Added file log.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <boost/log/sources/record_ostream.hpp>
|
||||
#include <boost/log/utility/manipulators/to_log.hpp>
|
||||
#include <boost/log/utility/setup/console.hpp>
|
||||
#include <boost/log/utility/setup/file.hpp>
|
||||
#include <boost/log/utility/setup/common_attributes.hpp>
|
||||
#include <boost/log/support/date_time.hpp>
|
||||
#include "conf.hpp"
|
||||
@@ -25,7 +26,7 @@ namespace hplog
|
||||
{
|
||||
|
||||
/**
|
||||
* Stream operator overload for converting integer severity vaue to text.
|
||||
* Stream operator overload for converting integer severity value to text.
|
||||
*/
|
||||
std::ostream &operator<<(std::ostream &os, LOG_SEVERITY level)
|
||||
{
|
||||
@@ -50,27 +51,52 @@ void init()
|
||||
else if (conf::cfg.loglevel == "error")
|
||||
severity = LOG_SEVERITY::ERROR;
|
||||
|
||||
// Log line format expression.
|
||||
auto format_expr = (expr::stream
|
||||
<< expr::format_date_time<boost::posix_time::ptime>("TimeStamp", "%Y-%m-%d %H:%M:%S")
|
||||
//<< ":" << expr::attr<boost::log::attributes::current_thread_id::value_type>("ThreadID")
|
||||
<< " [" << expr::attr<std::string>("Channel")
|
||||
<< "] [" << expr::attr<LOG_SEVERITY, severity_tag>("Severity")
|
||||
<< "] " << expr::smessage);
|
||||
|
||||
if (conf::cfg.loggers.count("console") == 1)
|
||||
{
|
||||
logging::add_console_log(
|
||||
std::clog,
|
||||
keywords::filter = (a_severity >= severity),
|
||||
keywords::format =
|
||||
(expr::stream
|
||||
<< expr::format_date_time<boost::posix_time::ptime>("TimeStamp", "%Y-%m-%d %H:%M:%S")
|
||||
//<< ":" << expr::attr<boost::log::attributes::current_thread_id::value_type>("ThreadID")
|
||||
<< " [" << expr::attr<std::string>("Channel")
|
||||
<< "] [" << expr::attr<LOG_SEVERITY, severity_tag>("Severity")
|
||||
<< "] " << expr::smessage));
|
||||
keywords::format = format_expr);
|
||||
}
|
||||
|
||||
if (conf::cfg.loggers.count("file") == 1)
|
||||
{
|
||||
// TODO: Add file logger.
|
||||
logging::add_file_log(
|
||||
keywords::target = conf::ctx.logDir, // Log file directory.
|
||||
keywords::file_name = conf::ctx.logDir + "/hp_%N.log", // File name pattern "hp_1.log".
|
||||
keywords::rotation_size = 10 * 1024 * 1024, // Rotate files every 10 MB.
|
||||
keywords::max_size = 500 * 1024 * 1024, // Do not exceed 500 MB total logs.
|
||||
keywords::filter = (a_severity >= severity),
|
||||
keywords::format = format_expr,
|
||||
|
||||
// This will make every new launch of Hot Pocket to start a new log file number.
|
||||
// It will scan existing log files matching the pattern and find the next number.
|
||||
keywords::scan_method = sinks::file::scan_matching,
|
||||
|
||||
#ifndef NDEBUG
|
||||
// We enable auto_flush to immediately get the logs onto the file. Otherwise it takes time
|
||||
// for buffered logs to reach the file. This impacts performance. So enabled only in debug build.
|
||||
keywords::auto_flush = true
|
||||
#endif
|
||||
);
|
||||
}
|
||||
|
||||
// Add Boost Log built-in fields for log entries.
|
||||
logging::add_common_attributes();
|
||||
}
|
||||
|
||||
void deinit()
|
||||
{
|
||||
// This will make all buffered logs to be flushed to the sink.
|
||||
logging::core::get()->remove_all_sinks();
|
||||
}
|
||||
|
||||
} // namespace hplog
|
||||
Reference in New Issue
Block a user