You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Michael Rumpf (Jira)" <ji...@apache.org> on 2020/03/23 13:23:00 UTC

[jira] [Commented] (LOG4J2-1794) Programmatic reconfiguration doesn't affect existing loggers

    [ https://issues.apache.org/jira/browse/LOG4J2-1794?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17064799#comment-17064799 ] 

Michael Rumpf commented on LOG4J2-1794:
---------------------------------------

The issue is the static block in the LogManager class that performs the initialization when the class LogManager is loaded. That happens through the private static final Logger field above.

> Programmatic reconfiguration doesn't affect existing loggers
> ------------------------------------------------------------
>
>                 Key: LOG4J2-1794
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1794
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Configurators
>    Affects Versions: 2.7
>            Reporter: Simon Cooper
>            Assignee: Ralph Goers
>            Priority: Major
>
> Sample code:
> {code}    private static final Logger Log = LogManager.getLogger();
>     public static void main(String[] args) throws Throwable {
>         ConfigurationBuilder<BuiltConfiguration> builder = ConfigurationBuilderFactory.newConfigurationBuilder();
>         builder.setConfigurationName("Test");
>         AppenderComponentBuilder console = builder.newAppender("Stdout", "Console")
>                 .add(builder.newLayout("PatternLayout").addAttribute("pattern", "Format: %m%n"));
>         builder.add(console);
>         builder.add(builder.newRootLogger(Level.INFO).add(builder.newAppenderRef("Stdout")));
>         Configurator.initialize(builder.build());
>         Configurator.setRootLevel(Level.INFO);
>         LogManager.getLogger().info("Log!");
>     }{code}
> The log statement at the bottom doesn't use the specified format, it uses the existing format. If the {{private static final Log = ...}} statement at the top is commented out, the log *does* use the reconfigured format.
> Reconfiguring the log settings should affect any loggers already created. Waiting until the logging is configured before creating any loggers is not always feasible - for example, if your entrypoint class has a static {{Logger}} and the reconfiguration is being done by a library you're calling into.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)