Hello Community!
I have a problem using Apache's Log4j logging functionality.
The configuration file looks as follows:
="1.0"="UTF-8"
<Configuration status="warn" name="hd.myproject" monitorInterval="120">
<Appenders>
<RollingFile name="HDRollingFile" filename="logs/hd.myproject.log"
filePattern="logs/hd.myproject.%d{yyyy-MM-dd}.%i.log.gz" ignoreExceptions="false"
immediateFlush="true">
<PatternLayout>
<pattern>%d{yyyy-mm-dd HH:mm:ss.SSS} [%t] %-5level %C.%M(%F:%L) - %msg%n%throwable{full}</pattern>
</PatternLayout>
<SizeBasedTriggeringPolicy size="8 MB"/>
</RollingFile>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<JDBC name="HDDatabase" tableName="APPLICATION_LOG">
<ConnectionFactory class="com.hidensity.data.ConnectionFactory" method="getDatabaseConnection"/>
<Column name="EVENT_DATE" isEventTimestamp="true" />
<Column name="LEVEL" pattern="%level" />
<Column name="LOGGER" pattern="%logger" />
<Column name="FILENAME" pattern="%file" />
<Column name="LINE" pattern="%line" />
<Column name="MESSAGE" pattern="%message" />
<Column name="THROWABLE" pattern="%ex{full}" />
</JDBC>
<Failover name="HDFailover" primary="HDDatabase" ignoreExceptions="false">
<Failovers>
<AppenderRef ref="HDRollingFile" level="trace"/>
<AppenderRef ref="Console"/>
</Failovers>
</Failover>
</Appenders>
<Loggers>
<Logger name="com.hidensity" level="trace" additivity="false">
<AppenderRef ref="HDFailover"/>
</Logger>
<Root level="error">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
As seen, the primary logger shall write the information to a database table. This works fine.
The problem occurs when the logger cannot write to the database.
As I understand the "Failover" logger, it should use the "HDRollingFile" logger in this situation. But after the program has ended, the Log-file is still empty.
With the
Configuration status="warn"
level, I get the following error:
ERROR appender Failover has no parameter that matches element Failovers
But this code is exactly like the code in the Log4j2 documentation.
The result is, the exceptions for the database not being accessible, are printed to the console, but none of my logging information I am generating in my program code.
Does anybody have a clue what is going on here and how to fix it?
Thanks in advance. :)