spdlog icon indicating copy to clipboard operation
spdlog copied to clipboard

spdlog can't flush to file immediately on windows11

Open aiyolo opened this issue 1 year ago • 2 comments

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);

aiyolo avatar Jun 26 '24 04:06 aiyolo

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 avatar Jun 26 '24 10:06 tt4g

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

tt4g avatar Jun 26 '24 11:06 tt4g

Same problem

ccjimmy777 avatar Jan 25 '25 02:01 ccjimmy777