diff options
Diffstat (limited to 'src/core/GpgCoreInit.cpp')
-rw-r--r-- | src/core/GpgCoreInit.cpp | 74 |
1 files changed, 36 insertions, 38 deletions
diff --git a/src/core/GpgCoreInit.cpp b/src/core/GpgCoreInit.cpp index 9ccc693d..d757c10c 100644 --- a/src/core/GpgCoreInit.cpp +++ b/src/core/GpgCoreInit.cpp @@ -25,16 +25,17 @@ * SPDX-License-Identifier: GPL-3.0-or-later * */ - #include "GpgCoreInit.h" +#include <spdlog/async.h> +#include <spdlog/common.h> +#include <spdlog/sinks/rotating_file_sink.h> +#include <spdlog/sinks/stdout_color_sinks.h> + #include "GpgFunctionObject.h" #include "core/GpgContext.h" #include "core/function/GlobalSettingStation.h" -// init easyloggingpp library -INITIALIZE_EASYLOGGINGPP - namespace GpgFrontend { /** @@ -45,36 +46,34 @@ void InitLoggingSystem() { using namespace boost::posix_time; using namespace boost::gregorian; - el::Loggers::addFlag(el::LoggingFlag::AutoSpacing); - el::Loggers::addFlag(el::LoggingFlag::ColoredTerminalOutput); - el::Loggers::addFlag(el::LoggingFlag::StrictLogFileSizeCheck); - el::Configurations defaultConf; - defaultConf.setToDefault(); - - // apply settings - defaultConf.setGlobally(el::ConfigurationType::Format, - "%datetime %level [core] {%func} -> %msg"); - - // apply settings no written to file - defaultConf.setGlobally(el::ConfigurationType::ToFile, "false"); - - // set the logger - el::Loggers::reconfigureLogger("default", defaultConf); - // get the log directory - auto logfile_path = (GlobalSettingStation::GetInstance().GetLogDir() / - to_iso_string(second_clock::local_time())); + auto logfile_path = + (GlobalSettingStation::GetInstance().GetLogDir() / "core"); logfile_path.replace_extension(".log"); - defaultConf.setGlobally(el::ConfigurationType::Filename, - logfile_path.u8string()); - - // apply settings written to file - defaultConf.setGlobally(el::ConfigurationType::ToFile, "true"); - - // set the logger - el::Loggers::reconfigureLogger("default", defaultConf); - LOG(INFO) << _("log file path") << logfile_path; + // sinks + std::vector<spdlog::sink_ptr> sinks; + sinks.push_back(std::make_shared<spdlog::sinks::stderr_color_sink_mt>()); + sinks.push_back(std::make_shared<spdlog::sinks::rotating_file_sink_mt>( + logfile_path.u8string(), 1048576 * 32, 8)); + + // thread pool + spdlog::init_thread_pool(1024, 2); + + // logger + auto core_logger = std::make_shared<spdlog::async_logger>( + "core", begin(sinks), end(sinks), spdlog::thread_pool()); + core_logger->set_pattern( + "[%H:%M:%S.%e] [T:%t] [%=4n] %^[%=8l]%$ [%s:%#] [%!] -> %v (+%ius)"); + +#ifdef DEBUG + core_logger->set_level(spdlog::level::trace); +#elif + core_logger->set_level(spdlog::level::info); +#endif + + // register it as default logger + spdlog::set_default_logger(core_logger); } void ResetGpgFrontendCore() { reset_gpgfrontend_core(); } @@ -89,12 +88,11 @@ void init_gpgfrontend_core() { use_custom_key_database_path = settings.lookup("general.use_custom_key_database_path"); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") - << _("use_custom_key_database_path"); + SPDLOG_ERROR("setting operation error: use_custom_key_database_path"); } - LOG(INFO) << "core loaded if use custom key databse path: " - << use_custom_key_database_path; + SPDLOG_INFO("core loaded if use custom key databse path: {}", + use_custom_key_database_path); std::string custom_key_database_path; try { @@ -104,11 +102,11 @@ void init_gpgfrontend_core() { settings.lookup("general.custom_key_database_path")); } catch (...) { - LOG(ERROR) << _("Setting Operation Error") << _("custom_key_database_path"); + SPDLOG_ERROR("setting operation error: custom_key_database_path"); } - LOG(INFO) << "core loaded custom key databse path: " - << custom_key_database_path; + SPDLOG_INFO("core loaded custom key databse path: {}", + custom_key_database_path); // init default channel GpgFrontend::GpgContext::CreateInstance( |