Skip to content

Commit

Permalink
Bypass spdlog singleton registry (#23)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Santiago Paunovic <ivanpauno@ekumenlabs.com>
  • Loading branch information
ivanpauno authored Dec 10, 2019
1 parent 3955fc4 commit baeb143
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions rcl_logging_spdlog/src/rcl_logging_spdlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <cinttypes>
#include <memory>
#include <mutex>
#include <utility>

#include "spdlog/spdlog.h"
#include "spdlog/sinks/basic_file_sink.h"
Expand All @@ -38,7 +39,7 @@ extern "C" {
#endif

static std::mutex g_logger_mutex;
static std::shared_ptr<spdlog::logger> g_root_logger = nullptr;
static std::unique_ptr<spdlog::logger> g_root_logger = nullptr;

static spdlog::level::level_enum map_external_log_level_to_library_level(int external_level)
{
Expand Down Expand Up @@ -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<spdlog::sinks::basic_file_sink_mt>(name_buffer, false);
g_root_logger = std::make_unique<spdlog::logger>("root", std::move(sink));

g_root_logger->set_pattern("%v");
}

Expand All @@ -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;
}

Expand Down

0 comments on commit baeb143

Please sign in to comment.