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

ASF subversion and git services commented on LOG4J2-3334:
---------------------------------------------------------

Commit f11dc6df9ae6367d96b73aed77e6e8c84e4cb4c7 in logging-log4j2's branch 
refs/heads/master from Ralph Goers
[ https://gitbox.apache.org/repos/asf?p=logging-log4j2.git;h=f11dc6d ]

LOG4J2-3334 - Create test to try to verify the problem


> Configurator.setLevel adding an incomplete LoggerConfig
> -------------------------------------------------------
>
>                 Key: LOG4J2-3334
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3334
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 2.17.1
>            Reporter: Mircea Lemnaru
>            Priority: Major
>
> I am trying to set the log levels for my application programatically and I 
> was using the method: *Configurator.setLevel*
>  
> {code:java}
> private static boolean setLevel(final String loggerName, final Level level, 
> final Configuration config) {
>     boolean set;
>     LoggerConfig loggerConfig = config.getLoggerConfig(loggerName);
>     if (!loggerName.equals(loggerConfig.getName())) {
>         // TODO Should additivity be inherited?
>         loggerConfig = new LoggerConfig(loggerName, level, true);
>         config.addLogger(loggerName, loggerConfig);
>         loggerConfig.setLevel(level);
>         set = true;
>     } else {
>         set = setLevel(loggerConfig, level);
>     }
>     return set;
> } {code}
> In my applicationI have the following loggers structure:
>  
> *com.myapp.service* -> set on TRACE from XML config
> Then I have the class: com.myapp.service.common.ServiceUtils with a logger 
> defined for it like this: {{Logger log = 
> LogManager.getLogger(this.getClass());}}
> And in this class, a bunch of log statements on *TRACE*
> Then I am trying to set the log level to *INFO* for the whole 
> com.myapp.service.common package. To suppress the *TRACE* logs for example.
> If I do this , Configurator will do the following:
>  # will try to fetch a LoggerConfig for the *common* package
>  # because there is nothing defined for that package only for the parent ... 
> it will return the config for that package
>  # because the names differ it will create a new LogConfig with the new 
> logger name and level but {color:#FF0000}without any appenders or appenders 
> refs{color}
>  # then it will add this to the config and reload loggers
> At this moment the logs from the end class are not printed anymore.
> Now , I again set the level for com.myapp.service.common logger , but this 
> time to {*}TRACE{*}. In order to re-enable the logs.
> Still , I can't see anything in the logs.
> After investigating it seems that adding the LoggerConfig without the 
> appenders copied from parent , is causing this behaviour.
> If for example I change the setLevel method to also add the appender refs and 
> appenders when creating the LoggerConfig object , everything is good and 
> logging works as expected.
>  Thank you



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to