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

Mike Li commented on LOG4J2-3295:
---------------------------------

It is understandable of the error message. But the major issue is that the 
reconfiguration process was blocked and the updated log4j2.xml configuration 
file never take effect without restarting the application. The correct behavior 
would be to reconfigure successfully even with the error message posted. Once 
the reconfiguration succeeds, new logs should be written to the file following 
the configurations in the updated log4j2.xml file.

> Reconfiguration error
> ---------------------
>
>                 Key: LOG4J2-3295
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3295
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: Configuration, Configurators
>    Affects Versions: 2.17.0
>            Reporter: Mike Li
>            Priority: Blocker
>
> Steps to recreate:
>  # start with log4j2.xml with following content:
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="DEBUG" monitorInterval="30">
>  
>     <Appenders>
>     <File name="FILE" fileName="c:\temp\product.log">
>         <PatternLayout>
>             <Pattern>ProductName:%-10p %d\{yyyy-MM-dd HH:mm:ss.SSS}
> {GMT} context:%x [%t] - %-50m - %M(%F:%L)%n</Pattern>
>         </PatternLayout>
>         
>     </File>
>     </Appenders>
>     <Loggers>
>         <Root level="INFO">
>             <AppenderRef ref="FILE"/>
>         </Root>
>     </Loggers>
> </Configuration>
>  
> 2. After the application is started and running, edit the log4j2.xml file 
> with the following content, notice that the fileName in the WRAP appender is 
> the same as that in the original FILE appender.
>  
> <?xml version="1.0" encoding="UTF-8"?>
> <Configuration status="DEBUG" monitorInterval="30" >
>     <Appenders>
>     <Async name="ASYNC" includeLocation="true" bufferSize="4096">
>         <AppenderRef ref="WRAP"/>
>     </Async>
>     <RollingFile name="WRAP" fileName="c:\temp\product.log" 
> filePattern="c:\temp\product.log.%i">
>         <PatternLayout pattern="ProductName:%-7p %d\{yyyy-MM-dd 
> HH:mm:ss.SSS}{GMT}
> context:%x [%t] - %-50m - %M(%F:%L)%n"/>
>         <Policies>
>             <SizeBasedTriggeringPolicy size="1048576"/>
>         </Policies>
>         <DefaultRolloverStrategy max="4"/>
>     </RollingFile>
>     </Appenders>
>     <Loggers>
>         <Root level="DEBUG">
>             <AppenderRef ref="ASYNC"/>
>         </Root>
>     </Loggers>
> </Configuration>
>  
> 3. Wait for the log4j to detect the change in 30 seconds to reconfigure. When 
> the reconfigure starts, it reports an error. Here is the exception stack:
>  
> 2021-12-28 17:42:41,688 Log4j2-TF-1-ConfiguratonFileWatcher-4 ERROR Could not 
> create plugin of type class 
> org.apache.logging.log4j.core.appender.RollingFileAppender for element 
> RollingFile org.apache.logging.log4j.core.config.ConfigurationException: 
> Configuration has multiple incompatible Appenders pointing to the same 
> resource 'c:\temp\product.log'
>     at 
> org.apache.logging.log4j.core.appender.AbstractManager.narrow(AbstractManager.java:169)
>     at 
> org.apache.logging.log4j.core.appender.rolling.RollingFileManager.getFileManager(RollingFileManager.java:217)
>     at 
> org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:146)
>     at 
> org.apache.logging.log4j.core.appender.RollingFileAppender$Builder.build(RollingFileAppender.java:62)
>     at 
> org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
>     at 
> org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1107)
>     at 
> org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1032)
>     at 
> org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1024)
>     at 
> org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:643)
>     at 
> org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:243)
>     at 
> org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:289)
>     at 
> org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:626)
>     at 
> org.apache.logging.log4j.core.LoggerContext.onChange(LoggerContext.java:762)
>     at 
> org.apache.logging.log4j.core.util.AbstractWatcher$ReconfigurationRunnable.run(AbstractWatcher.java:93)
>     at java.base/java.lang.Thread.run(Thread.java:831)



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

Reply via email to