tags:

views:

341

answers:

3

We have several java application server running here, with several apps. They all log with Log4J into the same file system, which we created only for that reason. From time to time it happens that the file system runs out of space and the app gets

log4j:ERROR Failed to flush writer,                                             
java.io.IOException

Unfortunately Log4J does not recover from this error, so that even after space is freed in the file system, no more logs are written from that app. Are there any options, programming-wise or setting-wise, to get Log4J going again, besides restarting the app?

+1  A: 

What do you see is an acceptable outcome here? I'd consider writing a new Appender that wraps whichever appender is accessing the disk, and tries to do something sensible when it detects IOExceptions. Maybe get it to wrap the underlying Appenders write methods in a try-catch block, and send you or a sysadmin an email.

GaryF
From what I gather from http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/helpers/OnlyOnceErrorHandler.html the error is thrown once and after that it's over. What I would wish for is that, although the error is thrown only once, the appender continues to try to write to that file system... maybe with 5 minute pauses... it seems like a wrapper around the appender is a viable idea
dertoni
If you're using the OnlyOnceErrorHandler, you might consider using the FallbackErrorHandler (http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/varia/FallbackErrorHandler.html) instead. That way you can specify a second appender (maybe an email appender) when the first can't write any more. That'll handle a lot of what wrapping would do.
GaryF
A: 

limit the size of your logs and try using a custom appender to archive logs to a backup machine with lots of disk space.

A: 

at Lazy: That would be only solving the syndroms, not the cause. The Problem is no blocking file but the disability of log4j to recover from a fault, so that Log4j goes on with logging. I ran into a similar failure, but not because of empty space but because of unreachable loggingfile. So, isn´t their any other way to reset the Logging from an IOException without writting a new Appender? And if it is not the right behaviour to post in an already answered thread, I want to refer to my own Question, which involves this kind of problem, too.