I have a web application that dumps logging information in a file using log4j RollingFileAppender. The application is currently configured to dump only WARN and higher logging information so that the disk I/O do not impact performance on the server.
However, I would like to know the last X debug information when an error occurs. Is there a way to configure log4j to dump the last 25 lines of debug information, as well as the error, in a file?
I presume this can be done using a custom appender. I tried searching for an example and could not find one.
I think writing your own is the way to go. Can you implement Appender and delegate each call to it to an underlying RollingFileAppender ?
In your implementation simply store the most recent ‘n’ log messages, and write through to the rolling file appender. If you encounter an error message, then dump your stored debug messages to the rolling file appender.