diff --git a/src/hpfs/hpfs.cpp b/src/hpfs/hpfs.cpp index c78d8cad..dd9c568e 100644 --- a/src/hpfs/hpfs.cpp +++ b/src/hpfs/hpfs.cpp @@ -6,14 +6,18 @@ namespace hpfs { - constexpr const char *HPFS_TRACE_ARG = "trace=none"; + constexpr const char *HPFS_TRACE_ARG_ERROR = "trace=error"; + constexpr const char *HPFS_TRACE_ARG_DEBUG = "trace=debug"; constexpr uint16_t INIT_CHECK_INTERVAL = 20; pid_t merge_pid = 0; bool init_success = false; + const char *active_hpfs_trace_arg; int init() { + active_hpfs_trace_arg = (conf::cfg.loglevel == "debug" ? HPFS_TRACE_ARG_DEBUG : HPFS_TRACE_ARG_ERROR); + LOG_INFO << "Starting hpfs merge process..."; if (start_merge_process() == -1) return -1; @@ -59,7 +63,7 @@ namespace hpfs conf::ctx.hpfs_exe_path.data(), (char *)"merge", conf::ctx.state_dir.data(), - (char *)HPFS_TRACE_ARG, + (char *)active_hpfs_trace_arg, NULL}; const int ret = execv(execv_args[0], execv_args); @@ -157,7 +161,7 @@ namespace hpfs conf::ctx.state_dir.data(), mount_dir.data(), (char *)(hash_map_enabled ? "hmap=true" : "hmap=false"), - (char *)HPFS_TRACE_ARG, + (char *)active_hpfs_trace_arg, NULL}; const int ret = execv(execv_args[0], execv_args); diff --git a/src/hplog.cpp b/src/hplog.cpp index 9bf8ff36..369204ec 100644 --- a/src/hplog.cpp +++ b/src/hplog.cpp @@ -12,78 +12,79 @@ namespace keywords = boost::log::keywords; namespace hplog { -/** + /** * Stream operator overload for converting integer severity value to text. */ -std::ostream &operator<<(std::ostream &os, LOG_SEVERITY level) -{ - static std::string_view loglevels[] = {"dbg", "inf", "wrn", "err"}; - os << loglevels[level]; - return os; -} - -// Severity attribute value tag type -struct severity_tag; - -void init() -{ - // Set log severity level based on contract config. - LOG_SEVERITY severity = LOG_SEVERITY::WARN; - if (conf::cfg.loglevel == "debug") - severity = LOG_SEVERITY::DEBUG; - else if (conf::cfg.loglevel == "info") - severity = LOG_SEVERITY::INFO; - else if (conf::cfg.loglevel == "warn") - severity = LOG_SEVERITY::WARN; - else if (conf::cfg.loglevel == "error") - severity = LOG_SEVERITY::ERROR; - - // Log line format expression. - const auto format_expr = (expr::stream - << expr::format_date_time("TimeStamp", "%Y%m%d %H:%M:%S ") - // << ":" << expr::attr("ThreadID") - // << "[" << expr::attr("Channel") << "] " - << "[" << expr::attr("Severity") << "] " - << expr::smessage); - - if (conf::cfg.loggers.count("console") == 1) + std::ostream &operator<<(std::ostream &os, LOG_SEVERITY level) { - logging::add_console_log( - std::clog, - keywords::filter = (a_severity >= severity), - keywords::format = format_expr); + static std::string_view loglevels[] = {"dbg", "inf", "wrn", "err"}; + os << loglevels[level]; + return os; } - if (conf::cfg.loggers.count("file") == 1) - { - logging::add_file_log( - keywords::target = conf::ctx.log_dir, // Log file directory. - keywords::file_name = conf::ctx.log_dir + "/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, + // Severity attribute value tag type + struct severity_tag; - // 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 + void init() + { + // Set log severity level based on contract config. + LOG_SEVERITY severity = LOG_SEVERITY::WARN; + if (conf::cfg.loglevel == "debug") + severity = LOG_SEVERITY::DEBUG; + else if (conf::cfg.loglevel == "info") + severity = LOG_SEVERITY::INFO; + else if (conf::cfg.loglevel == "warn") + severity = LOG_SEVERITY::WARN; + else if (conf::cfg.loglevel == "error") + severity = LOG_SEVERITY::ERROR; + + // Log line format expression. + const auto format_expr = (expr::stream + << expr::format_date_time("TimeStamp", "%Y%m%d %H:%M:%S ") + // << ":" << expr::attr("ThreadID") + // << "[" << expr::attr("Channel") << "] " + << "[" << expr::attr("Severity") << "][hp] " + << expr::smessage); + + if (conf::cfg.loggers.count("console") == 1) + { + logging::add_console_log( + std::clog, + keywords::filter = (a_severity >= severity), + keywords::format = format_expr); + } + + if (conf::cfg.loggers.count("file") == 1) + { + logging::add_file_log( + keywords::target = conf::ctx.log_dir, // Log file directory. + keywords::file_name = conf::ctx.log_dir + "/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 + // 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(); } - // 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(); -} + void deinit() + { + // This will make all buffered logs to be flushed to the sink. + logging::core::get()->remove_all_sinks(); + } } // namespace hplog \ No newline at end of file diff --git a/test/bin/hpfs b/test/bin/hpfs index 02e34e96..26d07d5c 100755 Binary files a/test/bin/hpfs and b/test/bin/hpfs differ