Skip to content

Commit 663e39d

Browse files
author
Omer Bulut
committed
fix: completely suppress spdlog file rotation errors with global error handler
1 parent bf17d94 commit 663e39d

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

Logger.hpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,17 @@ class Logger {
161161
// File sink setup
162162
if (!config.logFilePath.empty()) {
163163
try {
164-
// Suppress spdlog file rotation errors by setting environment variable
165-
setenv("SPDLOG_LEVEL", "warn", 1);
164+
// Suppress spdlog file rotation errors by setting environment variables
165+
setenv("SPDLOG_LEVEL", "error", 1); // Only show errors, not warnings
166+
setenv("SPDLOG_ERROR_LEVEL", "critical", 1); // Only show critical errors
167+
168+
// Set global spdlog error handler to suppress file rotation warnings
169+
spdlog::set_error_handler([](const std::string& msg) {
170+
// Only log critical errors, ignore file rotation warnings
171+
if (msg.find("rotating_file_sink") == std::string::npos) {
172+
std::cerr << "spdlog error: " << msg << std::endl;
173+
}
174+
});
166175

167176
// Ensure directory exists and is writable
168177
std::filesystem::path logPath(config.logFilePath);

0 commit comments

Comments
 (0)