Log4j 2
  1. Log4j 2
  2. LOG4J2-469

FailoverAppender does not retry back for Primary target

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-beta9
    • Fix Version/s: 2.0-rc2
    • Component/s: Appenders
    • Labels:
    • Environment:

      JBoss 6.1.1, Spring-MVC, Log4j2 beta-9, Windows 7, Eclipse Kelper

      Description

      Hi,

      In my product, I am using log4j2 for logging onto MySQL database. For that I am using JDBC as Primary and RollingRandomAccessFile as Secondary Appender.
      It works well and logs goes to Secondary appender when Primary appender fails (due to MySQL connection lost). But when MySQL connection comes back, it does not logs back to MySQL until I restart the JBoss Server.
      Is this a expected behavior? Or I am missing something in configuration file.

      Following is the my log4j2.xml file.

          <?xml version="1.0" encoding="UTF-8"?>
      <Configuration status="error">
      	<Appenders>
      		<JDBC name="databaseAppender" tableName="system_log" ignoreExceptions="false" bufferSize="10">
      			<DriverManager url="jdbc:mysql://localhost:3306/xxxid_db"
      				username="root" password="xxxxxxwing" />
      			<Column name="log_id" pattern="%x" />
      			<Column name="log_dated" isEventTimestamp="true" />
      			<Column name="log_logger" pattern="%logger" />
      			<Column name="log_level" pattern="%level" />
      			<Column name="log_message" pattern="%message" />
      			<Column name="log_throwable" pattern="%ex{full}" />
      		</JDBC>
      		<RollingRandomAccessFile name="RollingRandomAccessFile"
      			fileName="${sys:jboss.server.log.dir}/app.log" filePattern="${sys:jboss.server.log.dir}/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz">
      			<PatternLayout>
      				<Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
      			</PatternLayout>
      			<Policies>
      				<TimeBasedTriggeringPolicy />
      				<SizeBasedTriggeringPolicy size="250 MB" />
      			</Policies>
      		</RollingRandomAccessFile>
      		<Failover name="Failover" primary="databaseAppender" ignoreExceptions="false">
      			<Failovers>
      				<AppenderRef ref="RollingRandomAccessFile" />
      			</Failovers>
      		</Failover>
      	</Appenders>
      	<Loggers>
      		<Root level="warn">
      			<AppenderRef ref="Failover" />
      		</Root>
      	</Loggers>
      </Configuration>
      

      Thank You,
      Indrajit

        Issue Links

          Activity

          Hide
          Ralph Goers added a comment -

          In looking at the code I definitely see a problem, although not exactly what you are are reporting. Once a failure occurs a boolean flag is set. The failover appender will retry the primary appender periodically (the interval is controlled by the retryInterval attribute which defaults to 60 seconds). However, when the primary is again successful the flag is not reset. Instead, every subsequent call is going to try the primary, discover it doesn't work (or that it does) and then go to the failover via exception handling instead of waiting for the next retry interval.

          The problem you are experiencing is more than likely that the JDBC Appender may not be attempting to reconnect after the connection database connection fails.

          Show
          Ralph Goers added a comment - In looking at the code I definitely see a problem, although not exactly what you are are reporting. Once a failure occurs a boolean flag is set. The failover appender will retry the primary appender periodically (the interval is controlled by the retryInterval attribute which defaults to 60 seconds). However, when the primary is again successful the flag is not reset. Instead, every subsequent call is going to try the primary, discover it doesn't work (or that it does) and then go to the failover via exception handling instead of waiting for the next retry interval. The problem you are experiencing is more than likely that the JDBC Appender may not be attempting to reconnect after the connection database connection fails.
          Hide
          Indrajit Pingale added a comment -

          Thanks Ralph for quick reply.
          You are correct, JDBC Appender is not reconnecting after 60 seconds/ retrying to connect at every logger event. So do you have any suggestion over this (workaround/strategy)?

          Thanks again.

          Show
          Indrajit Pingale added a comment - Thanks Ralph for quick reply. You are correct, JDBC Appender is not reconnecting after 60 seconds/ retrying to connect at every logger event. So do you have any suggestion over this (workaround/strategy)? Thanks again.
          Hide
          Ralph Goers added a comment -

          The JDBC connection issue was resolved in LOG4J2-407

          Show
          Ralph Goers added a comment - The JDBC connection issue was resolved in LOG4J2-407
          Hide
          Ralph Goers added a comment -

          Fix for FailoverAppender applied in revision 1593892. Please verify and close.

          Show
          Ralph Goers added a comment - Fix for FailoverAppender applied in revision 1593892. Please verify and close.

            People

            • Assignee:
              Ralph Goers
              Reporter:
              Indrajit Pingale
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development