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 2020/04/17 04:27:00 UTC

[jira] [Commented] (LOG4J2-2821) updateLoggers with the same configuration?

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

Ralph Goers commented on LOG4J2-2821:
-------------------------------------

I've looked at this code and it doesn't make sense to me either. Maybe [~mattsicker] remembers why he did it this way, but I see several issues with this:
 # Any call to updateLoggers with a config that hasn't already saved the configuration in the LoggerContext is asking for problems. Log4j itself never does that. Doing so would mean Loggers could be pointing to a configuration that might never be saved.
 # Since Log4j always saves the configuration prior to calling this the old and "new" value will always be the same (as you noted).
 # setConfiguration also fires this event, so every reconfiguration is going to cause this event to fire twice. Obviously, that shouldn't happen. If updateLoggers is going to fire this event then it shouldn't happen in setConfiguration, but setConfiguration has the old configuration while updateLoggers does not, so updateLoggers can't really do it properly.

Many of the calls to updateLogger that apply to what LOG4J2-1206 was dealing with don't even actually have 2 configurations. They update the logging level in the current configuration (or similar) and then call updateLoggers to hvve the change take effect. Because they didn't save a copy of the old configuration (we don't provide an easy what to do that) they can't really fire the event with an old and new value, which is why I think this was missed.

To be honest, I am not even sure updateLoggers(config) should be public.

> updateLoggers with the same configuration?
> ------------------------------------------
>
>                 Key: LOG4J2-2821
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2821
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.6, 2.13.1
>            Reporter: LiYi
>            Priority: Major
>
> description: when we use the method updatetLoggers() in LoggerContext,  the old configuration is the same with the new configuration(i.e. The expression 'old == config' is always true), why do we need to update the configuration and fire a property change event?
> The code below is from LoggerContext, for your information.
> {code:java}
>     public void updateLoggers() {
>         updateLoggers(this.configuration);
>     }
>     public void updateLoggers(final Configuration config) {
>         final Configuration old = this.configuration;
>         for (final Logger logger : loggerRegistry.getLoggers()) {
>             logger.updateConfiguration(config);
>         }
>         firePropertyChangeEvent(new PropertyChangeEvent(this, PROPERTY_CONFIG, old, config));
>     }
> {code}
> ps: The behavior was imported from LOG4J2-1206.



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