Simon Cooper created LOG4J2-1794: ------------------------------------ Summary: 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
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") .addAttribute("follow", true) .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 (v6.3.4#6332) --------------------------------------------------------------------- To unsubscribe, e-mail: log4j-dev-unsubscr...@logging.apache.org For additional commands, e-mail: log4j-dev-h...@logging.apache.org