I am attempting to use log4j to write CSV files. The CSV header must be written to the top of a log file every time it is created. For example, all of these rolled files must have the following as the first line in the log file:
log.0 Timestamp, Name, min, max
log.1 Timestamp, Name, min, max
log.2 Timestamp, Name, min, max
Is it possible to determine when a rollover has occurred so that I can append the header?
Thanks.
P.S: I know there are lots of open source CSV writers but I prefer not to use them because I would like to use the existing log functionality in our software.
If you look at log4j documentation for RollingFileAppender, it has a method called rollOver.
http://logging.apache.org/log4j/1.2/apidocs/index.html
You would need to implement a custom file appender that inherits from RollingFileAppender, and override the rollOver method. I imagine you could just call super.rollOver, and then write whatever you want as a header to the new file before anything gets logged to it.