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

spdlog can't flush to file immediately on windows11 #3117

Open
aiyolo opened this issue Jun 26, 2024 · 2 comments
Open

spdlog can't flush to file immediately on windows11 #3117

aiyolo opened this issue Jun 26, 2024 · 2 comments

Comments

@aiyolo
Copy link

aiyolo commented Jun 26, 2024

I create two sinks, one is console sink and the other is file sink, the console sink can flush immediately, but the file sink always delay for multiple seconds, event though I had set flush strategy.

here is my code:

    // 输出到终端
    auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
    console_sink->set_level(spdlog::level::trace);
    console_sink->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%-5l%$] [%t] %v");

    // 输出到文件
    auto file_sink = std::make_shared<spdlog::sinks::daily_file_sink_mt>(
        "logs/app.log", 0, 0);
    file_sink->set_level(spdlog::level::trace);
    file_sink->set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%-5l%$] [%t] %v");

    // 设置默认logger
    std::vector<spdlog::sink_ptr> sinks{console_sink, file_sink};
    auto                          logger = std::make_shared<spdlog::logger>(
        "multi_sink", sinks.begin(), sinks.end());
    logger->set_level(spdlog::level::debug);
    spdlog::set_default_logger(logger);
    spdlog::flush_on(spdlog::level::debug);
@tt4g
Copy link
Contributor

tt4g commented Jun 26, 2024

but the file sink always delay for multiple seconds, event though I had set flush strategy.

I don't know what is going on because I don't know how to check the writes to the file.
Can you give me a specific way to check, for example, "When I monitor the log file with tail -f logs/app.log, the log display is a few seconds slower in the file than in the console"?

@tt4g
Copy link
Contributor

tt4g commented Jun 26, 2024

Regardless of the confirmation method, the following candidates are expected causes

  • Anti-virus software is preventing writing to the file
  • Slow disk operation due to heavy access
  • Cloud data synchronization, such as OneDrive, is slowing down writing to the file

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

2 participants