spdlog
spdlog copied to clipboard
spdlog can't flush to file immediately on windows11
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);
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"?
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
Same problem