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

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

Ralph,

For the reason why we are switching from File appender to a rolling file 
appender, we just provide the option to users and they do whatever they want. 
The appenders definition that I put in the discussion is just a sample to 
describe the issue without all the other complex settings like max file number 
and max file size in rolling file appender.

 

For your suggestion on reconfiguring to default configuration and then do 
another reconfiguration, it's complex in the following areas:
 # We need to know at the point when we need to do this. Today we reply on 
log4j2 to automatically detect the config file change and do the 
reconfiguration behind the scene. If we need to configure to default 
configuration first, then do another reconfiguration, then we need to plug some 
custom code at the point when this need to be done. Please guide me to a sample 
if you have on your hand.
 # At the point when the config file is updated, we need to determine whether 
such a reconfiguration to default is absolutely necessary by detecting whether 
the current configuration has the same log file name as the new configuration 
and the appenders are not compatible. This might be another part that is 
difficult to implement. If you have any sample code to do the detection, also 
send to me.

 

Thanks a lot.

> Reconfiguration failure with an 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