org.log5j
Class Level

java.lang.Object
  extended by org.log5j.Level
All Implemented Interfaces:
java.lang.Comparable<Level>

public final class Level
extends java.lang.Object
implements java.lang.Comparable<Level>

A logging level to compare when deciding whether to log a message. All logging levels can be represented as either a String or an int value.

Higher priority logging levels have lower values. The standard logging levels have the following values:

FATAL : 20
ERROR : 30
WARN : 40
INFO : 50
DEBUG : 60
TRACE : 70

ALL has a value of 100 and OFF has a value of 0 for obvious reasons.

Most programmers won't use this class directly but will set logging levels using a configuration class or file. A few may wish to implement custom logging levels if they need finer control than that afforded by the standard levels.

See the javadocs for the Level(String, int) constructor to find out how to create custome logging levels.

Author:
Bruce Ashton

Field Summary
static Level ALL
          Use this level to show all logging.
static Level DEBUG
          Log debug messages and above
static Level ERROR
          Log error messages and above.
static Level FATAL
          Log only fatal error messages.
static Level INFO
          Log info messages and above.
static Level OFF
          Use this level to turn off all logging.
static Level TRACE
          Log trace messages and above
static Level WARN
          Log warning messages and above.
 
Constructor Summary
Level(java.lang.String name, int value)
          Create a new logging level with the given name and int value between 1 and 100 inclusive.
 
Method Summary
 int compareTo(Level other)
          Compare this logging level with another.
 boolean equals(Level other)
          Returns true if the other Level has the same int value as this logging level.
 boolean equals(java.lang.Object o)
          Returns true if the argument o is a Level and has the same int value as this logging level.
 int hashCode()
          The hash code of a Level is its int value.
 java.lang.String toString()
          Returns String representation of this logging level, which is the same as the name.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ALL

public static final Level ALL
Use this level to show all logging.


TRACE

public static final Level TRACE
Log trace messages and above


DEBUG

public static final Level DEBUG
Log debug messages and above


INFO

public static final Level INFO
Log info messages and above.


WARN

public static final Level WARN
Log warning messages and above.


ERROR

public static final Level ERROR
Log error messages and above.


FATAL

public static final Level FATAL
Log only fatal error messages.


OFF

public static final Level OFF
Use this level to turn off all logging.

Constructor Detail

Level

public Level(java.lang.String name,
             int value)
Create a new logging level with the given name and int value between 1 and 100 inclusive. The smaller the int value the higher the priority.

new Levels must be created in a log5j config class. The log5j config class must extend Properties and the new Levels be instantiated just once in a parameterless constructor. For example,

 public class MyLog5jConfig extends Properties {
 
     public MyLog5jConfig() {
 
         new Level("MY_LOGGING_LEVEL", 55);
         setProperty("org.mycompany.MyClass.level", "MY_LOGGING_LEVEL");
     }
 }
 
Set the system property log5j.class to the fully qualified name of your config class to ensure that it is loaded during logging initialisation.

Parameters:
value - an int value for comparison with other logging levels; 1 <= value <= 100
name - the String representation of this logging level
Method Detail

compareTo

public int compareTo(Level other)
Compare this logging level with another.

Specified by:
compareTo in interface java.lang.Comparable<Level>
Parameters:
other - the other logging level
Returns:
the difference between the int value of this logging level and the other level.

equals

public boolean equals(Level other)
Returns true if the other Level has the same int value as this logging level.

Parameters:
other - another Level
Returns:
true if the other Level has the same int value as this logging level

equals

public boolean equals(java.lang.Object o)
Returns true if the argument o is a Level and has the same int value as this logging level.

Overrides:
equals in class java.lang.Object
Parameters:
o - an Object
Returns:
true if o is a Level and has the same int value as this logging level

hashCode

public int hashCode()
The hash code of a Level is its int value.

Overrides:
hashCode in class java.lang.Object
Returns:
the int value

toString

public java.lang.String toString()
Returns String representation of this logging level, which is the same as the name.

Overrides:
toString in class java.lang.Object
Returns:
the String representation of this logging level