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

LogLevel

public class LogLevel extends Object implements Serializable
The LogLevel class defines a set of standard logging levels. The logging Level objects are ordered and are specified by ordered integers. Enabling logging at a given level also enables logging at all higher levels.
author
Michael J. Sikorsky
author
Robert Shaw
author
Brent Sprecher
author
Richard Hurst
author
Brad Marlborough

Fields Summary
public static final LogLevel
FATAL
public static final LogLevel
ERROR
public static final LogLevel
WARN
public static final LogLevel
INFO
public static final LogLevel
DEBUG
public static final LogLevel
SEVERE
public static final LogLevel
WARNING
public static final LogLevel
CONFIG
public static final LogLevel
FINE
public static final LogLevel
FINER
public static final LogLevel
FINEST
protected String
_label
protected int
_precedence
private static LogLevel[]
_log4JLevels
private static LogLevel[]
_jdk14Levels
private static LogLevel[]
_allDefaultLevels
private static Map
_logLevelMap
private static Map
_logLevelColorMap
private static Map
_registeredLogLevelMap
Constructors Summary
public LogLevel(String label, int precedence)


  //--------------------------------------------------------------------------
  //   Constructors:
  //--------------------------------------------------------------------------
   
    _log4JLevels = new LogLevel[]{FATAL, ERROR, WARN, INFO, DEBUG};
    _jdk14Levels = new LogLevel[]{SEVERE, WARNING, INFO,
                                  CONFIG, FINE, FINER, FINEST};
    _allDefaultLevels = new LogLevel[]{FATAL, ERROR, WARN, INFO, DEBUG,
                                       SEVERE, WARNING, CONFIG, FINE, FINER, FINEST};

    _logLevelMap = new HashMap();
    for (int i = 0; i < _allDefaultLevels.length; i++) {
      _logLevelMap.put(_allDefaultLevels[i].getLabel(), _allDefaultLevels[i]);
    }

    // prepopulate map with levels and text color of black
    _logLevelColorMap = new HashMap();
    for (int i = 0; i < _allDefaultLevels.length; i++) {
      _logLevelColorMap.put(_allDefaultLevels[i], Color.black);
    }
  
    _label = label;
    _precedence = precedence;
  
Methods Summary
public booleanencompasses(org.apache.log4j.lf5.LogLevel level)
Returns true if the level supplied is encompassed by this level. For example, LogLevel.SEVERE encompasses no other LogLevels and LogLevel.FINE encompasses all other LogLevels. By definition, a LogLevel encompasses itself.

    if (level.getPrecedence() <= getPrecedence()) {
      return true;
    }

    return false;
  
public booleanequals(java.lang.Object o)

    boolean equals = false;

    if (o instanceof LogLevel) {
      if (this.getPrecedence() ==
          ((LogLevel) o).getPrecedence()) {
        equals = true;
      }

    }

    return equals;
  
public static java.util.ListgetAllDefaultLevels()

    return Arrays.asList(_allDefaultLevels);
  
public static java.util.ListgetJdk14Levels()

    return Arrays.asList(_jdk14Levels);
  
public java.lang.StringgetLabel()
Return the Label of the LogLevel.

    return _label;
  
public static java.util.ListgetLog4JLevels()

return
A List of LogLevel objects that map to log4j Priority objects.

    return Arrays.asList(_log4JLevels);
  
public static java.util.MapgetLogLevelColorMap()

    return _logLevelColorMap;
  
protected intgetPrecedence()

    return _precedence;
  
public inthashCode()

    return _label.hashCode();
  
public static org.apache.log4j.lf5.LogLevelregister(org.apache.log4j.lf5.LogLevel logLevel)
Registers a used defined LogLevel.

param
logLevel The log level to be registered. Cannot be a default LogLevel
return
LogLevel The replaced log level.

    if (logLevel == null) return null;

    // ensure that this is not a default log level
    if (_logLevelMap.get(logLevel.getLabel()) == null) {
      return (LogLevel) _registeredLogLevelMap.put(logLevel.getLabel(), logLevel);
    }

    return null;
  
public static voidregister(org.apache.log4j.lf5.LogLevel[] logLevels)

    if (logLevels != null) {
      for (int i = 0; i < logLevels.length; i++) {
        register(logLevels[i]);
      }
    }
  
public static voidregister(java.util.List logLevels)

    if (logLevels != null) {
      Iterator it = logLevels.iterator();
      while (it.hasNext()) {
        register((LogLevel) it.next());
      }
    }
  
public static voidresetLogLevelColorMap()

    // empty the map
    _logLevelColorMap.clear();

    // repopulate map and reset text color black
    for (int i = 0; i < _allDefaultLevels.length; i++) {
      _logLevelColorMap.put(_allDefaultLevels[i], Color.black);
    }
  
public voidsetLogLevelColorMap(org.apache.log4j.lf5.LogLevel level, java.awt.Color color)

    // remove the old entry
    _logLevelColorMap.remove(level);
    // add the new color entry
    if (color == null) {
      color = Color.black;
    }
    _logLevelColorMap.put(level, color);
  
public java.lang.StringtoString()

    return _label;
  
public static org.apache.log4j.lf5.LogLevelvalueOf(java.lang.String level)
Convert a log level label into a LogLevel object.

param
level The label of a level to be converted into a LogLevel.
return
LogLevel The LogLevel with a label equal to level.
throws
LogLevelFormatException Is thrown when the level can not be converted into a LogLevel.

    LogLevel logLevel = null;
    if (level != null) {
      level = level.trim().toUpperCase();
      logLevel = (LogLevel) _logLevelMap.get(level);
    }

    // Didn't match, Check for registered LogLevels
    if (logLevel == null && _registeredLogLevelMap.size() > 0) {
      logLevel = (LogLevel) _registeredLogLevelMap.get(level);
    }

    if (logLevel == null) {
      StringBuffer buf = new StringBuffer();
      buf.append("Error while trying to parse (" + level + ") into");
      buf.append(" a LogLevel.");
      throw new LogLevelFormatException(buf.toString());
    }
    return logLevel;