Ability to set logger level for loggers that have non allowed in xml tags symbols

This commit is contained in:
Azat Khuzhin 2020-04-27 21:21:01 +03:00
parent 9ff0aaac9c
commit f767309574
2 changed files with 42 additions and 6 deletions

View File

@ -166,12 +166,29 @@ void Loggers::buildLoggers(Poco::Util::AbstractConfiguration & config, Poco::Log
logger.root().setChannel(logger.getChannel()); logger.root().setChannel(logger.getChannel());
// Explicitly specified log levels for specific loggers. // Explicitly specified log levels for specific loggers.
Poco::Util::AbstractConfiguration::Keys levels; {
config.keys("logger.levels", levels); Poco::Util::AbstractConfiguration::Keys loggers_level;
config.keys("logger.levels", loggers_level);
if (!levels.empty()) if (!loggers_level.empty())
for (const auto & level : levels) {
logger.root().get(level).setLevel(config.getString("logger.levels." + level, "trace")); for (const auto & key : loggers_level)
{
if (key == "logger" || key.starts_with("logger["))
{
const std::string name(config.getString("logger.levels." + key + ".name"));
const std::string level(config.getString("logger.levels." + key + ".level"));
logger.root().get(name).setLevel(level);
}
else
{
// Legacy syntax
const std::string level(config.getString("logger.levels." + key, "trace"));
logger.root().get(key).setLevel(level);
}
}
}
}
} }
void Loggers::closeLogs(Poco::Logger & logger) void Loggers::closeLogs(Poco::Logger & logger)

View File

@ -12,15 +12,34 @@
<count>10</count> <count>10</count>
<!-- <console>1</console> --> <!-- Default behavior is autodetection (log to console if not daemon mode and is tty) --> <!-- <console>1</console> --> <!-- Default behavior is autodetection (log to console if not daemon mode and is tty) -->
<!-- Per level overrides: <!-- Per level overrides (legacy):
For example to suppress logging of the ConfigReloader you can use: For example to suppress logging of the ConfigReloader you can use:
NOTE: levels.logger is reserved, see below.
--> -->
<!-- <!--
<levels> <levels>
<ConfigReloader>none</ConfigReloader> <ConfigReloader>none</ConfigReloader>
</levels> </levels>
--> -->
<!-- Per level overrides:
For example to suppress logging of the RBAC for default user you can use:
(But please note that the logger name maybe changed from version to version, even after minor upgrade)
-->
<!--
<levels>
<logger>
<name>ContextAccess (default)</name>
<level>none</level>
</logger>
<logger>
<name>DatabaseOrdinary (test)</name>
<level>none</level>
</logger>
</levels>
-->
</logger> </logger>
<!--display_name>production</display_name--> <!-- It is the name that will be shown in the client --> <!--display_name>production</display_name--> <!-- It is the name that will be shown in the client -->