Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-291

Failover appender doesn't fail over on JDBC appender error

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments


    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.0-beta7
    • 2.0-beta9
    • Appenders
    • None
    • Java version 1.6_045 and Oracle 11g database on 64-bit machine. It's running within eclipse but I don't think that should make a difference.


      When I configure a Failover appender using the jdbc appender as primary and console/file as secondary if I get a database error It prints something to System.err, but not to the file/console as expected.

      How to recreate:

      Make sure a jdbc appender works first.

      Prepare a configuration similar to the one below:

      <?xml version="1.0" encoding="UTF-8"?>
      <configuration status="WARN">
      <Jdbc name="HubManagerDatabaseLog" tablename="HUB_MANAGER_LOG">
      <ConnectionFactory class="com.somecompany.server.dal.DalCommon" method="getDatabaseInstanceConnection"/>
      <Column name="LOG_DATE" isEventTimestamp="true" />
      <Column name="LOG_THREAD" pattern="%thread" />
      <Column name="LOG_LEVEL" pattern="%level" />
      <Column name="LOG_CLASS" pattern="%logger" />
      <Column name="LOG_METHOD" pattern="%method" />
      <Column name="LOG_MESSAGE" pattern="%message" />
      <Column name="LOG_EXCEPTION" pattern="%exception" />
      <FastRollingFile name="HubManagerFileLog" filename="logs/HubManager.log" filePattern="logs/HubManager-%d


      <PatternLayout pattern="%d [%thread] %-5level %logger.%method - %message %exception%n" />
      <SizeBasedTriggeringPolicy size="5MB"/>
      <!-- <DefaultRolloverStrategy max="50"/> -->
      <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout pattern="%d [%thread] %-5level %logger.%method - %message %exception%n" />
      <Failover name="PrimaryDatabaseLoggingIfFailGoToFile" primary="HubManagerDatabaseLog" suppressExceptions="false">
      <appender-ref ref="HubManagerFileLog"/>

      <logger name="com.exzac" level="DEBUG">
      <appender-ref ref="PrimaryDatabaseLoggingIfFailGoToFile"/>
      <appender-ref ref="Console"/>
      <root level="DEBUG">

      Run the following in a test java class that correctly has the above xml configuration on the build path:

      import org.apache.logging.log4j.LogManager;
      import org.apache.logging.log4j.Logger;

      public class TestFailOverAppender {
      private static final Logger LOGGER = LogManager.getLogger(TestFailOverAppender.class);

      public static void main(final String[] args) {
      final String shortString = "FailOver Short message that should go to database";
      final StringBuilder longString = new StringBuilder(shortString);
      while (longString.length() < 4000)

      { longString.append(shortString); }

      LOGGER.info("FailOver short string after message");

      I have tried setting suppressExceptions as false/true. I have tried replacing the fileappender (which works normally) with just console instead and saw the same result. This may or may not be related to another JIRA issue I found, LOG4J2-126.

      If there is simply something wrong with my configuration please let me know. I tried following the documentation as much as possible. Thank you.



          This comment will be Viewable by All Users Viewable by All Users


            beamerblvd Nick Williams
            asaf.erlich Asaf Erlich
            0 Vote for this issue
            3 Start watching this issue




                Issue deployment