FileDocCategorySizeDatePackage
LogMonitorAdapter.javaAPI DocApache log4j 1.2.159131Sat Aug 25 00:09:38 BST 2007org.apache.log4j.lf5.util

LogMonitorAdapter

public class LogMonitorAdapter extends Object

LogMonitorAdapter facilitates the usage of the LogMonitor

author
Richard Hurst

Fields Summary
public static final int
LOG4J_LOG_LEVELS
public static final int
JDK14_LOG_LEVELS
private LogBrokerMonitor
_logMonitor
private LogLevel
_defaultLevel
Constructors Summary
private LogMonitorAdapter(List userDefinedLevels)


  //--------------------------------------------------------------------------
  //   Constructors:
  //--------------------------------------------------------------------------
     
    super();
    // set the default level to be the first entry in the list
    _defaultLevel = (LogLevel) userDefinedLevels.get(0);
    _logMonitor = new LogBrokerMonitor(userDefinedLevels);

    _logMonitor.setFrameSize(getDefaultMonitorWidth(),
        getDefaultMonitorHeight());
    _logMonitor.setFontSize(12);
    _logMonitor.show();
  
Methods Summary
public voidaddMessage(org.apache.log4j.lf5.LogRecord record)

Adds a LogRecord to the LogMonitor.

param
record The LogRecord object to be logged in the logging monitor.

    _logMonitor.addMessage(record);
  
public org.apache.log4j.lf5.LogLevelgetDefaultLevel()

Gets the default LogLevel for the Adapter.

return
LogLevel

    return _defaultLevel;
  
protected static intgetDefaultMonitorHeight()

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

    return (3 * getScreenWidth()) / 4;
  
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 org.apache.log4j.lf5.LogLevelgetSevereLevel()

Gets the current Severe LogLevel

return
LogLevel

    return AdapterLogRecord.getSevereLevel();
  
public voidlog(java.lang.String category, org.apache.log4j.lf5.LogLevel level, java.lang.String message, java.lang.Throwable t, java.lang.String NDC)

Log a complete message to the Monitor.

param
category The category to be used
param
level The log level to apply to the message
param
message The message
param
t The throwable content of the message
param
NDC The NDC really only applies to Log4J and the parameter can usually be ignored.

    AdapterLogRecord record = new AdapterLogRecord();
    record.setCategory(category);
    record.setMessage(message);
    record.setNDC(NDC);
    record.setThrown(t);

    if (level == null) {
      record.setLevel(getDefaultLevel());
    } else {
      record.setLevel(level);
    }

    addMessage(record);
  
public voidlog(java.lang.String category, java.lang.String message)

Log a message to the Monitor and use the default LogLevel.

param
category The category to be used
param
message The message

    log(category, null, message);
  
public voidlog(java.lang.String category, org.apache.log4j.lf5.LogLevel level, java.lang.String message, java.lang.String NDC)

Log a message to the Monitor.

param
category The category to be used
param
level The log level to apply to the message
param
message The message
param
NDC

    log(category, level, message, null, NDC);
  
public voidlog(java.lang.String category, org.apache.log4j.lf5.LogLevel level, java.lang.String message, java.lang.Throwable t)

Log a message to the Monitor.

param
category The category to be used
param
level The log level to apply to the message
param
message The message
param
t The throwable content of the message

    log(category, level, message, t, null);
  
public voidlog(java.lang.String category, org.apache.log4j.lf5.LogLevel level, java.lang.String message)

Log a message to the Monitor.

param
category The category to be used
param
level The log level to apply to the message
param
message The message

    log(category, level, message, null, null);
  
public static org.apache.log4j.lf5.util.LogMonitorAdapternewInstance(int loglevels)

Creates an instance of LogMonitorAdapter using the log levels inticated by the parameter. Log4J and JDK1.4 both have default LogLevels which are set but these levels can be overriden.

param
loglevels An integer representing either Log4J or JDK1.4 logging levels
return
LogMonitorAdapter

    LogMonitorAdapter adapter;
    if (loglevels == JDK14_LOG_LEVELS) {
      adapter = newInstance(LogLevel.getJdk14Levels());
      adapter.setDefaultLevel(LogLevel.FINEST);
      adapter.setSevereLevel(LogLevel.SEVERE);
    } else {
      adapter = newInstance(LogLevel.getLog4JLevels());
      adapter.setDefaultLevel(LogLevel.DEBUG);
      adapter.setSevereLevel(LogLevel.FATAL);
    }
    return adapter;
  
public static org.apache.log4j.lf5.util.LogMonitorAdapternewInstance(org.apache.log4j.lf5.LogLevel[] userDefined)

Creates an instance of LogMonitorAdapter using the specified LogLevels. The first LogLevel in the array is used as the default LogLevel unless changed using the setDefaultLevel method.

param
userDefined An array of user defined LogLevel objects.
return
LogMonitorAdapter

    if (userDefined == null) {
      return null;
    }
    return newInstance(Arrays.asList(userDefined));
  
public static org.apache.log4j.lf5.util.LogMonitorAdapternewInstance(java.util.List userDefinedLevels)

Creates an instance of LogMonitorAdapter using the specified LogLevels. The first LogLevel in the List is used as the default LogLevel unless changed using the setDefaultLevel method.

param
userDefinedLevels A list of user defined LogLevel objects.
return
LogMonitorAdapter

    return new LogMonitorAdapter(userDefinedLevels);
  
public voidsetDefaultLevel(org.apache.log4j.lf5.LogLevel level)

Set the default log level to be used when logging messages without specifying a LogLevel.

param
level

    _defaultLevel = level;
  
public voidsetMaxNumberOfRecords(int maxNumberOfRecords)

Set the maximum number of records to be displayed in the monitor

param
maxNumberOfRecords

    _logMonitor.setMaxNumberOfLogRecords(maxNumberOfRecords);
  
public voidsetSevereLevel(org.apache.log4j.lf5.LogLevel level)

Sets the Severe LogLevel.

param
level

    AdapterLogRecord.setSevereLevel(level);