You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Ralph Goers (Jira)" <ji...@apache.org> on 2023/01/16 06:09: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=17677167#comment-17677167 ]
Ralph Goers commented on LOG4J2-1794:
-------------------------------------
Configurator.initialize() will essentially be a noop in this case. Simply replace it with.
{code:java}
Configurator.reconfigure(builder.build())
{code}
I will be updating the Javadoc to indicate that the initialize calls that accept a Configuration will be ignored if the LoggerContext has already been configured.
> 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.20.10#820010)