Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RCL_LOGGING_DISABLE_FILE_WRITING to disable file logging #106

Open
wants to merge 1 commit into
base: rolling
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions rcl_logging_spdlog/src/rcl_logging_spdlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ rcl_logging_ret_t rcl_logging_external_initialize(
const char * config_file,
rcutils_allocator_t allocator)
{
try {
if ("1" == rcpputils::get_env_var("RCL_LOGGING_DISABLE_FILE_WRITING")) {
// explicitly true
return RCL_LOGGING_RET_OK;
}
} catch (const std::runtime_error & error) {
}

std::lock_guard<std::mutex> lk(g_logger_mutex);
// It is possible for this to get called more than once in a process (some of
// the tests do this implicitly by calling rclcpp::init more than once).
Expand Down Expand Up @@ -196,22 +204,27 @@ rcl_logging_ret_t rcl_logging_external_initialize(

rcl_logging_ret_t rcl_logging_external_shutdown()
{
spdlog::drop("root");
g_root_logger = nullptr;
if (g_root_logger != nullptr) {
spdlog::drop("root");
g_root_logger = nullptr;
}
return RCL_LOGGING_RET_OK;
}

void rcl_logging_external_log(int severity, const char * name, const char * msg)
{
(void)name;
g_root_logger->log(map_external_log_level_to_library_level(severity), msg);
if (g_root_logger != nullptr) {
g_root_logger->log(map_external_log_level_to_library_level(severity), msg);
}
}

rcl_logging_ret_t rcl_logging_external_set_logger_level(const char * name, int level)
{
(void)name;

g_root_logger->set_level(map_external_log_level_to_library_level(level));
if (g_root_logger != nullptr) {
g_root_logger->set_level(map_external_log_level_to_library_level(level));
}

return RCL_LOGGING_RET_OK;
}