diff options
author | Saturneric <[email protected]> | 2023-02-03 13:43:55 +0000 |
---|---|---|
committer | Saturneric <[email protected]> | 2023-02-03 13:43:55 +0000 |
commit | 11d32517c2f6f538209c893c6b0b24572fba1a36 (patch) | |
tree | 0dac14bcad75d9c7c5b5723dc23e6409721966b4 /src/init.cpp | |
parent | feat: change logging framework to spdlog (diff) | |
download | GpgFrontend-11d32517c2f6f538209c893c6b0b24572fba1a36.tar.gz GpgFrontend-11d32517c2f6f538209c893c6b0b24572fba1a36.zip |
feat: change the log style in source files
Diffstat (limited to '')
-rw-r--r-- | src/init.cpp | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/src/init.cpp b/src/init.cpp index c872170e..20f033e0 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -26,21 +26,38 @@ * */ +#include <spdlog/async.h> +#include <spdlog/common.h> +#include <spdlog/sinks/rotating_file_sink.h> +#include <spdlog/sinks/stdout_color_sinks.h> + #include "GpgFrontend.h" #include "GpgFrontendBuildInfo.h" #include "core/function/GlobalSettingStation.h" void init_logging_system() { - el::Loggers::addFlag(el::LoggingFlag::AutoSpacing); - el::Configurations defaultConf; - defaultConf.setToDefault(); - - // apply settings - defaultConf.setGlobally(el::ConfigurationType::Format, - "%datetime %level [main] %func %msg"); - // apply settings no written to file - defaultConf.setGlobally(el::ConfigurationType::ToFile, "false"); - - // set the logger - el::Loggers::reconfigureLogger("default", defaultConf); + using namespace boost::posix_time; + using namespace boost::gregorian; + + // sinks + std::vector<spdlog::sink_ptr> sinks; + sinks.push_back(std::make_shared<spdlog::sinks::stderr_color_sink_mt>()); + + // thread pool + spdlog::init_thread_pool(1024, 2); + + // logger + auto main_logger = std::make_shared<spdlog::async_logger>( + "core", begin(sinks), end(sinks), spdlog::thread_pool()); + main_logger->set_pattern( + "[%H:%M:%S.%e] [T:%t] [%=4n] %^[%=8l]%$ [%s:%#] [%!] -> %v (+%ius)"); + +#ifdef DEBUG + main_logger->set_level(spdlog::level::trace); +#elif + core_logger->set_level(spdlog::level::info); +#endif + + // register it as default logger + spdlog::set_default_logger(main_logger); } |