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

Log Cache #119

Open
CTGUMARK opened this issue Aug 16, 2024 · 2 comments
Open

Log Cache #119

CTGUMARK opened this issue Aug 16, 2024 · 2 comments
Assignees

Comments

@CTGUMARK
Copy link

After the program is started, the log size is 0. It will not be written to the log until the program is closed. Is there a cache mechanism? Will it be written to the log file only when it reaches a certain size? How to write in real time

@Barry-Xu-2018
Copy link

By default, if the environment variable RCL_LOGGING_SPDLOG_EXPERIMENTAL_OLD_FLUSHING_BEHAVIOR is not set, the default flush time is 5 seconds. Setting this environment variable uses the old default value, which maybe 3 seconds.

Currently, no interface is provided to specify flush time from the outside. So, you can only modify the code yourself.

Besides changing the flush time, you can also modify the flush_on() setting. Currently, error logs trigger an automatic flush. You can change it to spdlog::level::info so that info logs (and higher levels like warning and error) will trigger the flush action.

BTW, frequent file writing is generally not recommended.

auto sink = std::make_unique<spdlog::sinks::basic_file_sink_mt>(name_buffer, false);
g_root_logger = std::make_shared<spdlog::logger>("root", std::move(sink));
if (!should_use_old_flushing_behavior) {
// in this case we should do the new thing (until config files are supported)
// which is to configure the logger to flush periodically and on
// error level messages
spdlog::flush_every(std::chrono::seconds(5));
g_root_logger->flush_on(spdlog::level::err);
} else {
// the old behavior is to not configure the sink at all, so do nothing
}

    auto sink = std::make_unique<spdlog::sinks::basic_file_sink_mt>(name_buffer, false);
    g_root_logger = std::make_shared<spdlog::logger>("root", std::move(sink));
    if (!should_use_old_flushing_behavior) {
      // in this case we should do the new thing (until config files are supported)
      // which is to configure the logger to flush periodically and on
      // error level messages
      spdlog::flush_every(std::chrono::seconds(5));
      g_root_logger->flush_on(spdlog::level::err);
    } else {
      // the old behavior is to not configure the sink at all, so do nothing
    }

@fujitatomoya fujitatomoya self-assigned this Aug 19, 2024
@fujitatomoya fujitatomoya transferred this issue from ros2/rcutils Aug 19, 2024
@fujitatomoya
Copy link
Collaborator

@Barry-Xu-2018 @CTGUMARK i moved this issue to rcl_logging since this is the issue with this repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants