There isn't an API where you can access a set of previous messages. However, Ceki describes a good approach in his book.
You can create a Filter that hangs on to the previous LogEvent and suppresses an incoming LogEvent if it is a duplicate. There is nothing to prevent you from buffering n number of messages (SMTPAppender does this), although you would need to probably hold on to a queue of unique messages if the duplicate messages aren't being logged one after another. I think this approach is more flexible than subclassing appender because you can attach the filter to any appender. Ken > -----Original Message----- > From: Shubhra [mailto:[EMAIL PROTECTED] > Sent: Wednesday, December 17, 2003 7:45 AM > To: [EMAIL PROTECTED] > Subject: How to detect duplicate messages in log4j > > > Hi All, > I have a client that sends a heartbeat to the server every 30 > seconds. If > the client is unable to connect to the server it prints the > message along > with the stack trace. This failure may persist for a while > and there is a > risk of filling up the log files. If I just note the failure, > there is a > risk of not being able to fully diagnose a problem later on. > > I want to detect repetitive error logging and instead log just a note > summarizing the failure *AFTER* the first error logging (with > the failure > reported in its entirety). > > To implement the above, I plan to create my own Appender that extends > RollingFileAppender and overwrites subAppend(LoggingEvent > event) . For a > duplicate message create a new LoggingEvent with Throwable > null else proceed > with original LoggingEvent. > > The problem is how to determine if a message is a duplicate? > Is there any API that lets me read all the events that have > occurred in last > 30 seconds, whereby I can do the comparison and leave out > stack trace of > duplicate messages. > > Regards, > Shubhra > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]