From eb478e38b26b6eb35fde9c3c1d4c9cba9d0802a1 Mon Sep 17 00:00:00 2001 From: tt4g Date: Mon, 25 Mar 2019 12:46:35 +0900 Subject: [PATCH] Add spdlog::initialize_logger --- include/spdlog/spdlog.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/spdlog/spdlog.h b/include/spdlog/spdlog.h index 20ff24be..79a75196 100644 --- a/include/spdlog/spdlog.h +++ b/include/spdlog/spdlog.h @@ -47,6 +47,21 @@ inline std::shared_ptr create(std::string logger_name, SinkArgs return default_factory::create(std::move(logger_name), std::forward(sink_args)...); } +// Initialize and register a logger, +// formatter and flush level will be set according the global settings. +// +// NOTE: +// Use this function when creating loggers manually. +// +// Example: +// auto console_sink = std::make_shared(); +// auto console_logger = std::make_shared("console_logger", console_sink); +// spdlog::initialize_logger(console_logger); +inline void initialize_logger(std::shared_ptr logger) +{ + details::registry::instance().initialize_logger(std::move(logger)); +} + // Return an existing logger or nullptr if a logger with such name doesn't // exist. // example: spdlog::get("my_logger")->info("hello {}", "world");