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 2021/12/29 06:52:00 UTC

[jira] [Commented] (LOG4J2-3295) Reconfiguration error

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

Ralph Goers commented on LOG4J2-3295:
-------------------------------------

This would be expected. Log4j does not "lose" log events. To accomplish that without having to block it creates the new configuration while everything is still logging to the old one. Once the new configuration is successfully created the Loggers will be modified to route events to the new configuration. After that is complete the old configuration will be stopped.  So this error message is the correct behavior

> 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)