FileDocCategorySizeDatePackage
LF5Appender.javaAPI DocApache log4j 1.2.158960Sat Aug 25 00:09:38 BST 2007org.apache.log4j.lf5

LF5Appender

public class LF5Appender extends AppenderSkeleton
LF5Appender logs events to a swing based logging console. The swing console supports turning categories on and off, multiple detail level views, as well as full text searching and many other capabilties.
author
Brent Sprecher

Fields Summary
protected LogBrokerMonitor
_logMonitor
protected static LogBrokerMonitor
_defaultLogMonitor
protected static AppenderFinalizer
_finalizer
Constructors Summary
public LF5Appender()
Constructs a LF5Appender using the default instance of the LogBrokerMonitor. This constructor should always be preferred over the LF5Appender(LogBrokerMonitor monitor) constructor, unless you need to spawn additional log monitoring windows.

    this(getDefaultInstance());
  
public LF5Appender(LogBrokerMonitor monitor)
Constructs a LF5Appender using an instance of a LogBrokerMonitor supplied by the user. This constructor should only be used when you need to spawn additional log monitoring windows.

param
monitor An instance of a LogBrokerMonitor created by the user.


    if (monitor != null) {
      _logMonitor = monitor;
    }
  
Methods Summary
public voidappend(org.apache.log4j.spi.LoggingEvent event)
Appends a LoggingEvent record to the LF5Appender.

param
event The LoggingEvent to be appended.

    // Retrieve the information from the log4j LoggingEvent.
    String category = event.getLoggerName();
    String logMessage = event.getRenderedMessage();
    String nestedDiagnosticContext = event.getNDC();
    String threadDescription = event.getThreadName();
    String level = event.getLevel().toString();
    long time = event.timeStamp;
    LocationInfo locationInfo = event.getLocationInformation();

    // Add the logging event information to a LogRecord
    Log4JLogRecord record = new Log4JLogRecord();

    record.setCategory(category);
    record.setMessage(logMessage);
    record.setLocation(locationInfo.fullInfo);
    record.setMillis(time);
    record.setThreadDescription(threadDescription);

    if (nestedDiagnosticContext != null) {
      record.setNDC(nestedDiagnosticContext);
    } else {
      record.setNDC("");
    }

    if (event.getThrowableInformation() != null) {
      record.setThrownStackTrace(event.getThrowableInformation());
    }

    try {
      record.setLevel(LogLevel.valueOf(level));
    } catch (LogLevelFormatException e) {
      // If the priority level doesn't match one of the predefined
      // log levels, then set the level to warning.
      record.setLevel(LogLevel.WARN);
    }

    if (_logMonitor != null) {
      _logMonitor.addMessage(record);
    }
  
public voidclose()
This method is an empty implementation of the close() method inherited from the org.apache.log4j.Appender interface.

  
public booleanequals(org.apache.log4j.lf5.LF5Appender compareTo)
The equals method compares two LF5Appenders and determines whether they are equal. Two Appenders will be considered equal if, and only if, they both contain references to the same LogBrokerMonitor.

param
compareTo A boolean value indicating whether the two LF5Appenders are equal.

    // If both reference the same LogBrokerMonitor, they are equal.
    return _logMonitor == compareTo.getLogBrokerMonitor();
  
protected static synchronized org.apache.log4j.lf5.viewer.LogBrokerMonitorgetDefaultInstance()

return
The default instance of the LogBrokerMonitor.

    if (_defaultLogMonitor == null) {
      try {
        _defaultLogMonitor =
            new LogBrokerMonitor(LogLevel.getLog4JLevels());
        _finalizer = new AppenderFinalizer(_defaultLogMonitor);

        _defaultLogMonitor.setFrameSize(getDefaultMonitorWidth(),
            getDefaultMonitorHeight());
        _defaultLogMonitor.setFontSize(12);
        _defaultLogMonitor.show();

      } catch (SecurityException e) {
        _defaultLogMonitor = null;
      }
    }

    return _defaultLogMonitor;
  
protected static intgetDefaultMonitorHeight()

    return (3 * getScreenHeight()) / 4;
  
protected static intgetDefaultMonitorWidth()

    return (3 * getScreenWidth()) / 4;
  
public org.apache.log4j.lf5.viewer.LogBrokerMonitorgetLogBrokerMonitor()

    return _logMonitor;
  
protected static intgetScreenHeight()

return
the screen height from Toolkit.getScreenSize() if possible, otherwise returns 600
see
java.awt.Toolkit

    try {
      return Toolkit.getDefaultToolkit().getScreenSize().height;
    } catch (Throwable t) {
      return 600;
    }
  
protected static intgetScreenWidth()

return
the screen width from Toolkit.getScreenSize() if possible, otherwise returns 800
see
java.awt.Toolkit

    try {
      return Toolkit.getDefaultToolkit().getScreenSize().width;
    } catch (Throwable t) {
      return 800;
    }
  
public static voidmain(java.lang.String[] args)

    new LF5Appender();
  
public booleanrequiresLayout()
Returns a value that indicates whether this appender requires a Layout. This method always returns false. No layout is required for the LF5Appender.

    return false;
  
public voidsetCallSystemExitOnClose(boolean callSystemExitOnClose)
This method is used to set the property that controls whether the LogBrokerMonitor is hidden or closed when a user exits the monitor. By default, the LogBrokerMonitor will hide itself when the log window is exited, and the swing thread will continue to run in the background. If this property is set to true, the LogBrokerMonitor will call System.exit(0) and will shut down swing thread and the virtual machine.

param
callSystemExitOnClose A boolean value indicating whether to call System.exit(0) when closing the log window.

    _logMonitor.setCallSystemExitOnClose(callSystemExitOnClose);
  
public voidsetMaxNumberOfRecords(int maxNumberOfRecords)

    _defaultLogMonitor.setMaxNumberOfLogRecords(maxNumberOfRecords);