I am working on a client-server-application and wanted to implement a flexible Loggingframework, so I chose log4j, which doesn´t really evolve anymore, but it is still handy framework.
Because the Logging happens along the network, i wanted a solution for the case, that the network drive isn´t available, so the Logger has to change its destination file(s).
Now I wanted to use the FallbackErrorHandler (configured with a XML-File) from the Log4j-library and the implementation worked: When my network drive isn´t available, it switches to a local Logfile, so no logging should be lost. But I headded two problems since yesterday and couldn´t figure or find out, how to solve it.
No return to initial Logging Configuration:
When the network drive is on again and the Logger could write to the old destinations, log4j still logs at the local drive and I can´t figure out, how to notify the original (primary) Logger to start again. I also tried to attach a second Appender to the ErrorHandler, which should mirror the failed primary Logger, that it tries to write on the network destination and when the network is on again, it logs in both files, on the local and on the network drive. But unfortunately it didn´t work out, I only got a failure message that the ErrorHandler-content doesn´t fit.
log4j:WARN The content of element type "errorHandler" must match "(param*,root-ref?,logger-ref*,appender-ref?)".
This is the responsible code.
<appender name="TraceAppender" class="org.apache.log4j.DailyRollingFileAppender">
<!-- The second appender-ref "TestAppender" leads to the error. -->
<errorHandler class="org.apache.log4j.varia.FallbackErrorHandler">
<logger-ref ref="com.idoh"/>
<appender-ref ref="TraceFallbackAppender"/>
<appender-ref ref="TestAppender"/>
</errorHandler>
<param name="datePattern" value=".yyyy-MM-dd" />
<param name="file" value="logs/Trace.txt" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-6r %d{HH:mm:ss,SSS} [%t] %-5p - %m%n"/>
</layout>
</appender>
So, how could I trigger log4j to reset to initial configuration or hold a second appender parallel to the "Local-Logger". My Application should work by itself and shouldn´t have to be restarted often.
First Error message is swallowed:
I recognized, that the first message, which leads to the switching between the primary logger and the FallbackErrorHandler (for example a logging-request to a readonly-File), is swallowed, so neither the primary logger logs it (because it can´t) nor the backup-Logger knows what it missed. So anybody else ran in this problem and could solve it? Or has any suggestions?