1

I'm having some trouble making log4j2 working with ActiveMQ.

Here is my log4j2.xml :

<Configuration>
<ThresholdFilter level="all"/>
    <Appenders>
        <Console name="STDOUT" target="SYSTEM_OUT">
            <PatternLayout pattern="%m%n"/>
                <Filters>
                    <ThresholdFilter level="info" />
                </Filters>
        </Console>

        <File name="baseLog" filename="\\\\p02630\\c$\\tmp\\logs\\logws-gendb.log">
            <PatternLayout>
                <Pattern>%d %p %c{1.} [%t] %m%n</Pattern>
              </PatternLayout>
            <Filters>
                <ThresholdFilter level="error"/>
            </Filters>
        </File>

    <JMS name="AMQError" providerurl="tcp://169.3.200.150:61616" password="admin" userName="admin">
        <factoryName>org.apache.activemq.jndi.ActiveMQInitialContextFactory</factoryName>
        <factoryBindingName>ConnectionFactory</factoryBindingName>
        <TopicBindingName>logError</TopicBindingName>
    </JMS>
    <Failover name="FailOverAMQ" primary="AMQError">
        <Failovers>
            <appender-ref ref="baseLog"/>
        </Failovers>
    </Failover>     
</Appenders>
<Loggers>
    <root>
        <AppenderRef ref="STDOUT" />
        <AppenderRef ref="baseLog" />
        <AppenderRef ref="FailOverAMQ" />
    </root>
</Loggers>
</Configuration>

Goal is to be able to log errors in ActiveMQ. But if/when the AMQ server's down, I want the logger to be able to reconnect automatically and to still log errors inside a file Appender.

While the server is running, everything is working fine. But when I shutdown the server, nor the ActiveMQ (normal), nor the file Appender are working and when the server comes back up, log4j is not autoreconnecting after the 60s auto reconnect time(default). More troubling, my file appender is not working anymore after server shutdown.

I first had a problem with the "no parameter that matches element Failovers" detailed here and tried to add the FallBack class registering the "Failovers" element. It did remove the error message but the failover appender is not working any better. I have the impression all this class did was obfuscating the error.

Have you had any luck working with Failover appenders ?

Thanks for the help.

C.Dumange
  • 128
  • 1
  • 8

1 Answers1

0

Just a quick follow up.

I could not found any solution to this problem. Seems to be a bug in log4j2.

In the end, I developped a short class using javax.jms package to manage my connection to ActiveMQ.

Not perfect but at least, it works.

C.Dumange
  • 128
  • 1
  • 8