From baeb143a1d264424760774bd6aba96f86974f6da Mon Sep 17 00:00:00 2001 From: Ivan Santiago Paunovic Date: Tue, 10 Dec 2019 13:38:38 -0300 Subject: [PATCH] Bypass spdlog singleton registry (#23) Signed-off-by: Ivan Santiago Paunovic --- rcl_logging_spdlog/src/rcl_logging_spdlog.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rcl_logging_spdlog/src/rcl_logging_spdlog.cpp b/rcl_logging_spdlog/src/rcl_logging_spdlog.cpp index 7738753..978498f 100644 --- a/rcl_logging_spdlog/src/rcl_logging_spdlog.cpp +++ b/rcl_logging_spdlog/src/rcl_logging_spdlog.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "spdlog/spdlog.h" #include "spdlog/sinks/basic_file_sink.h" @@ -38,7 +39,7 @@ extern "C" { #endif static std::mutex g_logger_mutex; -static std::shared_ptr g_root_logger = nullptr; +static std::unique_ptr g_root_logger = nullptr; static spdlog::level::level_enum map_external_log_level_to_library_level(int external_level) { @@ -142,7 +143,10 @@ rcl_logging_ret_t rcl_logging_external_initialize( RCUTILS_SET_ERROR_MSG("Failed to create log file name string"); return RCL_LOGGING_RET_ERROR; } - g_root_logger = spdlog::basic_logger_mt("root", name_buffer); + + auto sink = std::make_unique(name_buffer, false); + g_root_logger = std::make_unique("root", std::move(sink)); + g_root_logger->set_pattern("%v"); } @@ -152,7 +156,6 @@ rcl_logging_ret_t rcl_logging_external_initialize( rcl_logging_ret_t rcl_logging_external_shutdown() { g_root_logger = nullptr; - spdlog::drop("root"); return RCL_LOGGING_RET_OK; }