I'm looking at using log4j to do logging in our application. Multiple clients on different machines will be logging events. The Message object in the LoggingEvent class is an instance of a proprietary Log class that contains a date. The Log class implements ObjectRenderer and contains a Date object. The events are date based. Each day will have its own log file (This is a requirement). So far, I could have used log4j almost as is, implementing just the ObjectRenderer. But there is one requirement for which I have to do some specialisation.
For the most part, almost all the logging events will be for the current date, but occasionally, the date object in the message could be an earlier date. If I use FileAppender (or DailyRollingFileAppender) it will append all logs to the current log file. However I need to be able to append the event to a previous day's log file depending on the value of the date in the message. After going through the log4j code, I think I have to subclass FileAppender (or DailyRollingFileAppender) and redefine the "append" method to compare the file with the specified date and open the appropriate log file if required. (If I redefine the "subappend" method, the "checkEntryConditions" will have been done for the current date's file). My questions are 1. To begin with, is this the right approach? 2. Is "append" thread safe? I believe it is based on the synchronized code block in the "callAppenders" method of Category. But that's not the black box behaviour. Can I make assumptions based on existing code? I don't think so. But I wonder about performance if I have to set up synchronized blocks in my subclass. 3. Should I call "activateOptions" after setting the file name? I expected to see a call to "activateOptions" in the "rollover" method of the DailyRollingFileAppender class, but it seems it's getting called from somewhere else. Where? 4. The "setFile" method closes the file. So if I have interleaved logging events for different dates, this will be rather inefficient. I could redefine "reset" to no-op and close the files (from a list) in a redefined "rollover" method. Will this have some side-effect? Seems fragile. Might break in a later version of log4j. Regards Milind --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]