3

Since I discovered some performance issues with log4j 1.2.x, I tried migrating to log4j2.

Now I encountered a problem for which I can't find a solution. I have to rewrite the configuration file that was for log4j 1.2.x into a v2 compatible one. Problem occurs when I reached the property inside of an appender, called "errorHandler".

Here is where errorHandler appears in my log4j 1.2.x context:

<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
    <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
    <param name="Target" value="System.out"/>
    <param name="Threshold" value="WARN"/>
    <layout class="org.apache.log4j.PatternLayout">
        <param name="ConversionPattern" value="%d %-5p [%t] %c - %m%n"/>
    </layout>
</appender>

Could anybody tell me, which is the similar property, if exists one, in the log4j2 for errorHandler? Or maybe, another alternative in log4j2 that would give me the exactly same result?

Thanks in advance.

Ciobanu Andrei
  • 315
  • 3
  • 14

1 Answers1

2

Log4j2 provides a FailoverAppender that will invoke the secondary appender if the primary appender fails. You can have a list of secondary appenders and log4j will try all of them until one succeeds.

Note that when using a FailoverAppender you should configure your primary and secondary appenders with ignoreExceptions=false.

Remko Popma
  • 35,130
  • 11
  • 92
  • 114
  • ok, I had already looked over this FailoverAppender but not very carefully but if you said this could be the solution for my issue, I'll try again, and with more patience. Thanks. – Ciobanu Andrei May 21 '14 at 07:07
  • @Remko Popma i am unable to think how failover appender can help here, would you be generous in explaining that? – r_goyal Jan 18 '21 at 07:02
  • Because Failover appender just helps call secondary appenders if primary appender fails. Say i have primary appender as appender1, secondary as appender2, i want appender2 to be called when appender1 throws, but this i need to happen only once, next time all calls to appender2 via appender1 should just become NOOP – r_goyal Jan 18 '21 at 07:08
  • @r_goyal I am not familiar enough with the FailoverAppender design to answer your follow-up question; would you mind raising this on the Log4j2 mailing list? – Remko Popma Jan 18 '21 at 08:51