From 383b3e1891456c52e1beacfc8ec8e8744e5f4845 Mon Sep 17 00:00:00 2001 From: shareong <740310627@qq.com> Date: Fri, 15 Mar 2024 13:08:25 +0800 Subject: [PATCH] update log format --- bcos-utilities/BoostLogInitializer.cpp | 21 +++++++++++++++++++++ cmake/CompilerSettings.cmake | 1 - 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/bcos-utilities/BoostLogInitializer.cpp b/bcos-utilities/BoostLogInitializer.cpp index 5aa569f..d18aaaf 100644 --- a/bcos-utilities/BoostLogInitializer.cpp +++ b/bcos-utilities/BoostLogInitializer.cpp @@ -27,6 +27,8 @@ #include #include #include +#include +#include using namespace bcos; @@ -126,16 +128,35 @@ void BoostLogInitializer::initStatLog( void BoostLogInitializer::initLog(boost::property_tree::ptree const& _pt, std::string const& _logger, std::string const& _logPrefix) { + // replace ~ with %, because only % is used as escape character in boost log + char toReplace = '~'; + char replacement = '%'; + m_running.store(true); // get log level m_logLevel = getLogLevel(_pt.get("log.level", "info")); m_consoleLog = _pt.get("log.enable_console_output", false); + m_logFormat = _pt.get("log.format", ""); + std::replace_if( + m_logFormat.begin(), m_logFormat.end(), [&toReplace](char c) { return c == toReplace; }, + replacement); + m_logNamePattern = _pt.get("log.log_name_pattern", "log_%Y%m%d_%H%M.log"); + std::replace_if( + m_logNamePattern.begin(), m_logNamePattern.end(), + [&toReplace](char c) { return c == toReplace; }, replacement); + m_compressArchive = _pt.get("log.compress_archive_file", false); m_archivePath = _pt.get("log.archive_path", ""); + m_rotateFileNamePattern = _pt.get("log.rotate_name_pattern", "log_%Y%m%d%H.%M.log"); + + std::replace_if( + m_rotateFileNamePattern.begin(), m_rotateFileNamePattern.end(), + [&toReplace](char c) { return c == toReplace; }, replacement); + m_rotateSize = _pt.get("log.max_log_file_size", 1024) * MB_IN_BYTES; if (m_rotateSize < 100 * MB_IN_BYTES) { diff --git a/cmake/CompilerSettings.cmake b/cmake/CompilerSettings.cmake index 17c9e73..989aae8 100644 --- a/cmake/CompilerSettings.cmake +++ b/cmake/CompilerSettings.cmake @@ -40,7 +40,6 @@ if(("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR("${CMAKE_CXX_COMPILER_ID}" MATC add_compile_options(-Wno-unused-variable) add_compile_options(-Wno-unknown-pragmas) add_compile_options(-Wno-deprecated-declarations) - add_compile_options(-Wno-error=deprecated-declarations) add_compile_options(-fno-omit-frame-pointer) add_compile_options(-Wno-error=strict-aliasing)