sadmanmd opened a new issue, #3622:
URL: https://github.com/apache/logging-log4j2/issues/3622

   ## Description
   
   While working on Log4j2 Failover appender, I saw the failovers appenders not 
executing. I detail investigate the source code of FailoverAppender class and 
found the the private method name 'callAppender' is executing the 
primary.callAppender method and if error occur then the private failover method 
will execute. But the primary.callAppender method is not throwing any error so 
the private failover method never execute at all.
   
   Also if you check the public start method of FailoverAppender class, the 
logic says if the primary appender is null then it logs an error and the error 
counter is increased to one. For that the super class start method never 
executes and the FailoverAppender remains non started appender. Because of this 
if for some reason primary Failover appender not started or initiated in for 
any reason [like, file path not correct for RollingFile/File] the whole 
Failover appender will stop working and throw an non started appender error.
   
   ## Configuration
   
   **Version:** [Log4j version 2.20.0 - 2.24.3]
   
   **Operating system:** [Windows/Mac/Linux]
   
   **JDK:** [1.8,17]
   
   ## Logs
   
   ```
   Exception in thread "main" 
org.apache.logging.log4j.core.appender.AppenderLoggingException: Attempted to 
append to non-started appender MyFailoverAppender
        at 
org.apache.logging.log4j.core.config.AppenderControl.handleError(AppenderControl.java:147)
        at 
org.apache.logging.log4j.core.config.AppenderControl.ensureAppenderStarted(AppenderControl.java:140)
        at 
org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:132)
        at 
org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:125)
        at 
org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:89)
        at 
org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:683)
        at 
org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:641)
        at 
org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:624)
        at 
org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:560)
        at 
org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:82)
        at org.apache.logging.log4j.core.Logger.log(Logger.java:163)
        at 
org.apache.logging.log4j.spi.AbstractLogger.tryLogMessage(AbstractLogger.java:2168)
        at 
org.apache.logging.log4j.spi.AbstractLogger.logMessageTrackRecursion(AbstractLogger.java:2122)
        at 
org.apache.logging.log4j.spi.AbstractLogger.logMessageSafely(AbstractLogger.java:2105)
        at 
org.apache.logging.log4j.spi.AbstractLogger.logMessage(AbstractLogger.java:1980)
        at 
org.apache.logging.log4j.spi.AbstractLogger.logIfEnabled(AbstractLogger.java:1946)
        at 
org.apache.logging.log4j.spi.AbstractLogger.info(AbstractLogger.java:1283)
   ```
   
   ## Reproduction
   
   ```
   <?xml version="1.0" encoding="UTF-8"?>
   <Configuration status="DEBUG">
       <Appenders>
           <File name="PrimaryFileAppender" fileName="[USE AN INVALID 
PATH]/log/primary.log"
                 ignoreExceptions="false">
               <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level 
%logger{36} - %msg%n"/>
           </File>
   
           <Console name="BackupConsoleAppender" target="SYSTEM_OUT">
               <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level 
%logger{36} - %msg%n"/>
           </Console>
   
           <RollingFile name="BackupRollingFileAppender"
                        append="true"
                        fileName="./log/backup.log"
                        filePattern="backup-%d{yyyy-MM-dd}-%i.log.gz"
                        ignoreExceptions="false">
               <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level 
%logger{36} - %msg%n"/>
               <TimeBasedTriggeringPolicy interval="24" modulate="true"/>
               <SizeBasedTriggeringPolicy size="100 MB"/>
           </RollingFile>
   
           <Failover name="MyFailoverAppender" primary="PrimaryFileAppender" 
ignoreExceptions="false">
               <Failovers>
                   <!-- THIS APPENDERS NEVER EXECUTE -->
                   <AppenderRef ref="BackupConsoleAppender"/>
                   <AppenderRef ref="BackupRollingFileAppender"/>
               </Failovers>
           </Failover>
       </Appenders>
   
       <Loggers>
           <Root level="INFO">
               <AppenderRef ref="MyFailoverAppender"/>
           </Root>
       </Loggers>
   </Configuration>
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to