@@ -84,7 +84,7 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
8484
8585 Poco::AutoPtr<DB::OwnFormattingChannel> log = new DB::OwnFormattingChannel (pf, log_file);
8686 log->setLevel (log_level);
87- split->addChannel (log);
87+ split->addChannel (log, " log " );
8888 }
8989
9090 const auto errorlog_path = config.getString (" logger.errorlog" , " " );
@@ -116,7 +116,7 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
116116 Poco::AutoPtr<DB::OwnFormattingChannel> errorlog = new DB::OwnFormattingChannel (pf, error_log_file);
117117 errorlog->setLevel (errorlog_level);
118118 errorlog->open ();
119- split->addChannel (errorlog);
119+ split->addChannel (errorlog, " errorlog " );
120120 }
121121
122122 if (config.getBool (" logger.use_syslog" , false ))
@@ -155,7 +155,7 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
155155 Poco::AutoPtr<DB::OwnFormattingChannel> log = new DB::OwnFormattingChannel (pf, syslog_channel);
156156 log->setLevel (syslog_level);
157157
158- split->addChannel (log);
158+ split->addChannel (log, " syslog " );
159159 }
160160
161161 bool should_log_to_console = isatty (STDIN_FILENO) || isatty (STDERR_FILENO);
@@ -177,7 +177,7 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
177177 Poco::AutoPtr<DB::OwnFormattingChannel> log = new DB::OwnFormattingChannel (pf, new Poco::ConsoleChannel);
178178 logger.warning (" Logging " + console_log_level_string + " to console" );
179179 log->setLevel (console_log_level);
180- split->addChannel (log);
180+ split->addChannel (log, " console " );
181181 }
182182
183183 split->open ();
@@ -224,6 +224,89 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
224224 }
225225}
226226
227+ void Loggers::updateLevels (Poco::Util::AbstractConfiguration & config, Poco::Logger & logger)
228+ {
229+ int max_log_level = 0 ;
230+
231+ const auto log_level_string = config.getString (" logger.level" , " trace" );
232+ int log_level = Poco::Logger::parseLevel (log_level_string);
233+ if (log_level > max_log_level)
234+ max_log_level = log_level;
235+
236+ const auto log_path = config.getString (" logger.log" , " " );
237+ if (!log_path.empty ())
238+ split->setLevel (" log" , log_level);
239+ else
240+ split->setLevel (" log" , 0 );
241+
242+ // Set level to console
243+ bool is_daemon = config.getBool (" application.runAsDaemon" , false );
244+ bool should_log_to_console = isatty (STDIN_FILENO) || isatty (STDERR_FILENO);
245+ if (config.getBool (" logger.console" , false )
246+ || (!config.hasProperty (" logger.console" ) && !is_daemon && should_log_to_console))
247+ split->setLevel (" console" , log_level);
248+ else
249+ split->setLevel (" console" , 0 );
250+
251+ // Set level to errorlog
252+ int errorlog_level = 0 ;
253+ const auto errorlog_path = config.getString (" logger.errorlog" , " " );
254+ if (!errorlog_path.empty ())
255+ {
256+ errorlog_level = Poco::Logger::parseLevel (config.getString (" logger.errorlog_level" , " notice" ));
257+ if (errorlog_level > max_log_level)
258+ max_log_level = errorlog_level;
259+ }
260+ split->setLevel (" errorlog" , errorlog_level);
261+
262+ // Set level to syslog
263+ int syslog_level = 0 ;
264+ if (config.getBool (" logger.use_syslog" , false ))
265+ {
266+ syslog_level = Poco::Logger::parseLevel (config.getString (" logger.syslog_level" , log_level_string));
267+ if (syslog_level > max_log_level)
268+ max_log_level = syslog_level;
269+ }
270+ split->setLevel (" syslog" , syslog_level);
271+
272+ // Global logging level (it can be overridden for specific loggers).
273+ logger.setLevel (max_log_level);
274+
275+ // Set level to all already created loggers
276+ std::vector<std::string> names;
277+
278+ logger.root ().names (names);
279+ for (const auto & name : names)
280+ logger.root ().get (name).setLevel (max_log_level);
281+
282+ logger.root ().setLevel (max_log_level);
283+
284+ // Explicitly specified log levels for specific loggers.
285+ {
286+ Poco::Util::AbstractConfiguration::Keys loggers_level;
287+ config.keys (" logger.levels" , loggers_level);
288+
289+ if (!loggers_level.empty ())
290+ {
291+ for (const auto & key : loggers_level)
292+ {
293+ if (key == " logger" || key.starts_with (" logger[" ))
294+ {
295+ const std::string name (config.getString (" logger.levels." + key + " .name" ));
296+ const std::string level (config.getString (" logger.levels." + key + " .level" ));
297+ logger.root ().get (name).setLevel (level);
298+ }
299+ else
300+ {
301+ // Legacy syntax
302+ const std::string level (config.getString (" logger.levels." + key, " trace" ));
303+ logger.root ().get (key).setLevel (level);
304+ }
305+ }
306+ }
307+ }
308+ }
309+
227310void Loggers::closeLogs (Poco::Logger & logger)
228311{
229312 if (log_file)
0 commit comments