2 #include <spdlog/async.h> 3 #include <spdlog/sinks/rotating_file_sink.h> 4 #include <spdlog/sinks/stdout_color_sinks.h> 8 #define LOGGER_FACTORY_UNINITIALIZED (0) 9 #define LOGGER_FACTORY_INITIALIZING (1) 10 #define LOGGER_FACTORY_INITIALIZED (2) 18 const std::string &logger_name,
19 spdlog::level::level_enum log_level) {
20 std::vector<spdlog::sink_ptr> log_sinks;
21 log_sinks.push_back(std::make_shared<spdlog::sinks::rotating_file_sink_mt>(
22 logger_name +
".log",1L<<20, 3));
23 log_sinks.push_back(std::make_shared<spdlog::sinks::stdout_color_sink_mt>());
24 std::shared_ptr<spdlog::logger> log = std::make_shared<spdlog::async_logger>(
29 spdlog::async_overflow_policy::block);
30 spdlog::register_logger(log);
31 log->set_pattern(
"[%H:%M:%S.%f] [%n] [Thread %t] [%^%l%$] %v");
32 log->set_level(log_level);
43 spdlog::init_thread_pool(1L<<20, 1);
49 spdlog::level::from_str(default_log_level));
52 auto start_ms = std::chrono::duration_cast<std::chrono::microseconds>(
53 std::chrono::high_resolution_clock::now().time_since_epoch());
54 _default_logger->debug(
"Program start time (microseconds): {}", start_ms.count());
62 const std::string &logger_name,
63 spdlog::level::level_enum log_level) {
#define LOGGER_FACTORY_INITIALIZED
static std::shared_ptr< spdlog::logger > _default_logger
static std::shared_ptr< spdlog::logger > createLogger(const std::string &logger_name, spdlog::level::level_enum log_level=spdlog::level::info)
static void _initialize()
const std::string & getConfString(const std::string &key)
#define LOGGER_FACTORY_INITIALIZING
static std::shared_ptr< spdlog::details::thread_pool > _thread_pool_holder
#define LOGGER_FACTORY_UNINITIALIZED
static std::shared_ptr< spdlog::logger > & getDefaultLogger()
static std::atomic< uint32_t > _initialize_state
#define CONF_LOGGER_DEFAULT_LOG_LEVEL
#define CONF_LOGGER_DEFAULT_LOG_NAME
static std::shared_ptr< spdlog::logger > _create_logger(const std::string &logger_name, spdlog::level::level_enum log_level)