Hi Chris, On Tue, 28 Feb 2023 at 20:04, Christopher Schultz <ch...@christopherschultz.net> wrote: > What is the recommended technique for changing a single logger's > threshold in log4j2? I realize that the best thing to do would be to > "just configure it correctly the first time" but in reality, you > sometimes just have to enable TRACE logging in production to figure out > what the hell is happening.
The recommended approach is to dynamically update your configuration. Log4j2 Core does not lose events during a reconfiguration event. By setting a `monitorInterval` attribute on the `<Configuration>` component[1], Log4j2 will monitor your configuration source (anything with a Java URL handler) and reconfigure the logging system when it changes. Another approach is through global filters (filters directly attached to the Configuration object), that are evaluated *before* a logger's level. If they return ACCEPT or DENY, the message is unconditionally accepted or denied. Recently Ralph added the (undocumented?) MutableThreadContextMapFilter[2], which works like its documented counterpart[3], but regularly reads its configuration from an URL (configLocation attribute). This can be used e.g. to increase the logging level for a specific user dynamically. If you really require programmatic configuration, Configurator.setLevel[4] is the most stable way. As you noticed, Configuration#getLoggerConfig gives you the *effective* configuration of the logger, which could be the configuration of its parent or even the root logger. Piotr [1] https://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticReconfiguration [2] https://logging.apache.org/log4j/2.x/javadoc/log4j-core/org/apache/logging/log4j/core/filter/MutableThreadContextMapFilter.Builder.html [3] https://logging.apache.org/log4j/2.x/manual/filters.html#ThreadContextMapFilter [4] https://logging.apache.org/log4j/2.x/javadoc/log4j-core/org/apache/logging/log4j/core/config/Configurator.html --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-user-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-user-h...@logging.apache.org