fix: Fix default severity in Logger (#2449)

This commit is contained in:
Ayaz Salikhov
2025-08-18 16:04:54 +01:00
committed by GitHub
parent 57ac234657
commit 46c96654ee
2 changed files with 7 additions and 7 deletions

View File

@@ -227,6 +227,7 @@ LogService::init(config::ClioConfigDefinition const& config)
spdlog::drop_all(); spdlog::drop_all();
data.isAsync = config.get<bool>("log.is_async"); data.isAsync = config.get<bool>("log.is_async");
data.defaultSeverity = getSeverityLevel(config.get<std::string>("log.level"));
if (data.isAsync) { if (data.isAsync) {
spdlog::init_thread_pool(8192, 1); spdlog::init_thread_pool(8192, 1);
@@ -252,9 +253,8 @@ LogService::init(config::ClioConfigDefinition const& config)
data.allSinks.push_back(createFileSink(params)); data.allSinks.push_back(createFileSink(params));
} }
// get default severity, can be overridden per channel using the `log.channels` array // get min severity per channel, can be overridden using the `log.channels` array
auto const defaultSeverity = getSeverityLevel(config.get<std::string>("log.level")); auto const maybeMinSeverity = getMinSeverity(config, data.defaultSeverity);
auto const maybeMinSeverity = getMinSeverity(config, defaultSeverity);
if (!maybeMinSeverity) { if (!maybeMinSeverity) {
return std::unexpected{maybeMinSeverity.error()}; return std::unexpected{maybeMinSeverity.error()};
} }
@@ -263,7 +263,7 @@ LogService::init(config::ClioConfigDefinition const& config)
// Create loggers for each channel // Create loggers for each channel
for (auto const& channel : Logger::kCHANNELS) { for (auto const& channel : Logger::kCHANNELS) {
auto const it = minSeverity.find(channel); auto const it = minSeverity.find(channel);
auto const severity = (it != minSeverity.end()) ? it->second : defaultSeverity; auto const severity = (it != minSeverity.end()) ? it->second : data.defaultSeverity;
registerLogger(channel, severity); registerLogger(channel, severity);
} }
@@ -272,7 +272,7 @@ LogService::init(config::ClioConfigDefinition const& config)
std::string const format = config.get<std::string>("log.format"); std::string const format = config.get<std::string>("log.format");
spdlog::set_pattern(format); spdlog::set_pattern(format);
LOG(LogService::info()) << "Default log level = " << toString(defaultSeverity); LOG(LogService::info()) << "Default log level = " << toString(data.defaultSeverity);
return {}; return {};
} }

View File

@@ -242,7 +242,7 @@ private:
class LogService { class LogService {
struct Data { struct Data {
bool isAsync; bool isAsync;
Severity severity; Severity defaultSeverity;
std::vector<std::shared_ptr<spdlog::sinks::sink>> allSinks; std::vector<std::shared_ptr<spdlog::sinks::sink>> allSinks;
}; };
@@ -252,7 +252,7 @@ private:
static Data data; static Data data;
static std::shared_ptr<spdlog::logger> static std::shared_ptr<spdlog::logger>
registerLogger(std::string const& channel, Severity severity = data.severity); registerLogger(std::string const& channel, Severity severity = data.defaultSeverity);
public: public:
LogService() = delete; LogService() = delete;