dk.netarkivet.monitor.logging
Class CachingLogHandler

java.lang.Object
  extended by java.util.logging.Handler
      extended by dk.netarkivet.monitor.logging.CachingLogHandler

public class CachingLogHandler
extends java.util.logging.Handler

A LogHandler that keeps the last N messages in memory, and exposes each as a CachingLogRecordMBean.


Constructor Summary
CachingLogHandler()
          Initialise the handler datastructures, and register MBeans for all log records.
 
Method Summary
 void close()
          Close the Handler and free all associated resources.
 void flush()
          Does nothing.
 java.util.logging.LogRecord getNthLogRecord(int n)
          Returns the nth logrecord from the top.
 void publish(java.util.logging.LogRecord record)
          Publish a LogRecord.
 
Methods inherited from class java.util.logging.Handler
getEncoding, getErrorManager, getFilter, getFormatter, getLevel, isLoggable, reportError, setEncoding, setErrorManager, setFilter, setFormatter, setLevel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CachingLogHandler

public CachingLogHandler()
Initialise the handler datastructures, and register MBeans for all log records. Note this last thing is actually done in the constructor of the CachingLogRecord.

See Also:
SingleMBeanObject, The number of remembered log records is read from the setting Settings.LOGGING_HISTORY_SIZE
Method Detail

publish

public void publish(java.util.logging.LogRecord record)
Publish a LogRecord. This simply remembers the record in datastructures, and thus exposes it in an MBean.

Specified by:
publish in class java.util.logging.Handler
Parameters:
record - description of the log event. A null record is silently ignored and is not published
See Also:
Handler.publish(LogRecord)

flush

public void flush()
Does nothing. No flushing necessary in this handler.

Specified by:
flush in class java.util.logging.Handler

close

public void close()
           throws java.lang.SecurityException
Close the Handler and free all associated resources.

The close method will perform a flush and then close the Handler. After close has been called this Handler should no longer be used. Method calls may either be silently ignored or may throw runtime exceptions.

Specified by:
close in class java.util.logging.Handler
Throws:
java.lang.SecurityException - never.

getNthLogRecord

public java.util.logging.LogRecord getNthLogRecord(int n)
Returns the nth logrecord from the top.

Parameters:
n - The number of the log record to get
Returns:
The LogRecord which is number n from the top, or null for none.