Top Description Fields Constructors Methods
org.apache.logging.log4j

public final Class Level

extends Object
implements Comparable<Level>, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.lang.Comparable
Annotations
@BaselineIgnore:2.22.0
Static Imports
org.apache.logging.log4j.util.Strings.toRootUpperCase

Levels used for identifying the severity of an event. Levels are organized from most specific to least:

Level names with description
Name Description
OFF No events will be logged.
FATAL A fatal event that will prevent the application from continuing.
ERROR An error in the application, possibly recoverable.
WARN An event that might possible lead to an error.
INFO An event for informational purposes.
DEBUG A general debugging event.
TRACE A fine-grained debug message, typically capturing the flow through the application.
ALL All events should be logged.

Typically, configuring a level in a filter or on a logger will cause logging events of that level and those that are more specific to pass through the filter. A special level, ALL, is guaranteed to capture all levels when used in logging configurations.

Field Summary

Modifier and TypeField and Description
public static final Level
ALL

All events should be logged.

public static final String
CATEGORY

Category to be used by custom levels.

public static final Level
DEBUG

A general debugging event.

private static final Level[]
public static final Level
ERROR

An error in the application, possibly recoverable.

public static final Level
FATAL

A fatal event that will prevent the application from continuing.

public static final Level
INFO

An event for informational purposes.

private final int
private static final ConcurrentMap<String, Level>
private final String
public static final Level
OFF

No events will be logged.

private static final long
private final StandardLevel
public static final Level
TRACE

A fine-grained debug message, typically capturing the flow through the application.

public static final Level
WARN

An event that might possible lead to an error.

Constructor Summary

AccessConstructor and Description
private
Level(final String name, final int intLevel)

Method Summary

Modifier and TypeMethod and Description
public Level
clone()

Overrides java.lang.Object.clone.

Creates and returns a copy of this object.

public int
compareTo(final Level
the object to be compared.
other
)

Implements java.lang.Comparable.compareTo.

Compares this object with the specified object for order.

public boolean
equals(final Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public static Level

Returns:

The Level.
forName
(final String
The name of the level.
name
,
final int
The integer value for the Level. If the level was previously created this value is ignored.
intValue
)

Retrieves an existing Level or creates on if it didn't previously exist.

public Class<Level>
public static Level

Returns:

The Level or null.
getLevel
(final String
The name of the Level.
name
)

Return the Level associated with the name or null if the Level cannot be found.

public StandardLevel

Returns:

an enum of the standard Levels.
getStandardLevel
()

Gets the standard Level values as an enum.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public int

Returns:

the value of this Level.
intLevel
()

Gets the integral value of this Level.

public boolean

Returns:

True true if this level is in between the given levels
isInRange
(final Level
The minimum level to test.
minLevel
,
final Level
The maximum level to test.
maxLevel
)

Compares this level against the levels passed as arguments and returns true if this level is in between the given levels.

public boolean

Returns:

True if this level Level is less specific or the same as the given Level.
isLessSpecificThan
(final Level
The level to test.
level
)

Compares this level against the level passed as an argument and returns true if this level is the same or is less specific.

public boolean

Returns:

True if this level Level is more specific or the same as the given Level.
isMoreSpecificThan
(final Level
The level to test.
level
)

Compares this level against the level passed as an argument and returns true if this level is the same or is more specific.

public String

Returns:

the name of this Level.
name
()

Gets the symbolic name of this Level.

private Object
public static Level

Returns:

The Level associated with the String.
toLevel
(final String
The name of the desired Level.
level
)

Converts the string passed as argument to a level.

public static Level

Returns:

The Level associated with the String.
toLevel
(final String
The name of the desired Level.
name
,
final Level
The Level to use if the String is invalid.
defaultLevel
)

Converts the string passed as argument to a level.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public static Level

Returns:

The Level.
valueOf
(final String
The name of the Level to return.
name
)

Return the Level associated with the name.

public static <
The enum type whose constant is to be returned
T extends Enum<T>
>
T

Returns:

the enum constant of the specified enum type with the specified name
valueOf
(final Class<T>
the Class object of the enum type from which to return a constant
enumType
,
final String
the name of the constant to return
name
)

Returns the enum constant of the specified enum type with the specified name.

public static Level[]

Returns:

An array of Levels.
values
()

Return an array of all the Levels that have been registered.

Inherited from java.lang.Object:
finalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

ALLback to summary
public static final Level ALL

All events should be logged.

CATEGORYback to summary
public static final String CATEGORY

Category to be used by custom levels.

Since
2.1
DEBUGback to summary
public static final Level DEBUG

A general debugging event.

EMPTY_ARRAYback to summary
private static final Level[] EMPTY_ARRAY
ERRORback to summary
public static final Level ERROR

An error in the application, possibly recoverable.

FATALback to summary
public static final Level FATAL

A fatal event that will prevent the application from continuing.

INFOback to summary
public static final Level INFO

An event for informational purposes.

intLevelback to summary
private final int intLevel
LEVELSback to summary
private static final ConcurrentMap<String, Level> LEVELS
nameback to summary
private final String name
OFFback to summary
public static final Level OFF

No events will be logged.

serialVersionUIDback to summary
private static final long serialVersionUID
standardLevelback to summary
private final StandardLevel standardLevel
TRACEback to summary
public static final Level TRACE

A fine-grained debug message, typically capturing the flow through the application.

WARNback to summary
public static final Level WARN

An event that might possible lead to an error.

Constructor Detail

Levelback to summary
private Level(final String name, final int intLevel)

Method Detail

cloneback to summary
public Level clone() throws CloneNotSupportedException

Overrides java.lang.Object.clone.

Doc from java.lang.Object.clone.

Creates and returns a copy of this object. The precise meaning of "copy" may depend on the class of the object. The general intent is that, for any object x, the expression:

x.clone() != x
will be true, and that the expression:
x.clone().getClass() == x.getClass()
will be true, but these are not absolute requirements. While it is typically the case that:
x.clone().equals(x)
will be true, this is not an absolute requirement.

By convention, the returned object should be obtained by calling super.clone. If a class and all of its superclasses (except Object) obey this convention, it will be the case that x.clone().getClass() == x.getClass().

By convention, the object returned by this method should be independent of this object (which is being cloned). To achieve this independence, it may be necessary to modify one or more fields of the object returned by super.clone before returning it. Typically, this means copying any mutable objects that comprise the internal "deep structure" of the object being cloned and replacing the references to these objects with references to the copies. If a class contains only primitive fields or references to immutable objects, then it is usually the case that no fields in the object returned by super.clone need to be modified.

Returns:Level

a clone of this instance.

Annotations
@Override
@SuppressWarnings:CloneDoesntCallSuperClone
Exceptions
CloneNotSupportedException:
if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.
compareToback to summary
public int compareTo(final Level other)

Implements java.lang.Comparable.compareTo.

Doc from java.lang.Comparable.compareTo.

Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

The implementor must ensure signum(x.compareTo(y)) == -signum(y.compareTo(x)) for all x and y. (This implies that x.compareTo(y) must throw an exception if and only if y.compareTo(x) throws an exception.)

The implementor must also ensure that the relation is transitive: (x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0.

Finally, the implementor must ensure that x.compareTo(y)==0 implies that signum(x.compareTo(z)) == signum(y.compareTo(z)), for all z.

Parameters
other:Level

the object to be compared.

Returns:int

a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Annotations
@Override
equalsback to summary
public boolean equals(final Object other)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
other:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
forNameback to summary
public static Level forName(final String name, final int intValue)

Retrieves an existing Level or creates on if it didn't previously exist.

Parameters
name:String

The name of the level.

intValue:int

The integer value for the Level. If the level was previously created this value is ignored.

Returns:Level

The Level.

Exceptions
IllegalArgumentException:
if the name is null or intValue is less than zero.
getDeclaringClassback to summary
public Class<Level> getDeclaringClass()
getLevelback to summary
public static Level getLevel(final String name)

Return the Level associated with the name or null if the Level cannot be found.

Parameters
name:String

The name of the Level.

Returns:Level

The Level or null.

Exceptions
IllegalArgumentException:
if the name is null.
getStandardLevelback to summary
public StandardLevel getStandardLevel()

Gets the standard Level values as an enum.

Returns:StandardLevel

an enum of the standard Levels.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
intLevelback to summary
public int intLevel()

Gets the integral value of this Level.

Returns:int

the value of this Level.

isInRangeback to summary
public boolean isInRange(final Level minLevel, final Level maxLevel)

Compares this level against the levels passed as arguments and returns true if this level is in between the given levels.

Parameters
minLevel:Level

The minimum level to test.

maxLevel:Level

The maximum level to test.

Returns:boolean

True true if this level is in between the given levels

Since
2.4
isLessSpecificThanback to summary
public boolean isLessSpecificThan(final Level level)

Compares this level against the level passed as an argument and returns true if this level is the same or is less specific.

Concretely, ALL is less specific than TRACE, which is less specific than DEBUG, which is less specific than INFO, which is less specific than WARN, which is less specific than ERROR, which is less specific than FATAL, and finally OFF, which is the most specific standard level.

Parameters
level:Level

The level to test.

Returns:boolean

True if this level Level is less specific or the same as the given Level.

isMoreSpecificThanback to summary
public boolean isMoreSpecificThan(final Level level)

Compares this level against the level passed as an argument and returns true if this level is the same or is more specific.

Concretely, FATAL is more specific than ERROR, which is more specific than WARN, etc., until TRACE, and finally ALL, which is the least specific standard level. The most specific level is OFF.

Parameters
level:Level

The level to test.

Returns:boolean

True if this level Level is more specific or the same as the given Level.

nameback to summary
public String name()

Gets the symbolic name of this Level. Equivalent to calling toString().

Returns:String

the name of this Level.

readResolveback to summary
private Object readResolve()
toLevelback to summary
public static Level toLevel(final String level)

Converts the string passed as argument to a level. If the conversion fails, then this method returns DEBUG.

Parameters
level:String

The name of the desired Level.

Returns:Level

The Level associated with the String.

toLevelback to summary
public static Level toLevel(final String name, final Level defaultLevel)

Converts the string passed as argument to a level. If the conversion fails, then this method returns the value of defaultLevel.

Parameters
name:String

The name of the desired Level.

defaultLevel:Level

The Level to use if the String is invalid.

Returns:Level

The Level associated with the String.

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
valueOfback to summary
public static Level valueOf(final String name)

Return the Level associated with the name.

Parameters
name:String

The name of the Level to return.

Returns:Level

The Level.

Exceptions
NullPointerException:
if the Level name is null.
IllegalArgumentException:
if the Level name is not registered.
valueOfback to summary
public static <T extends Enum<T>> T valueOf(final Class<T> enumType, final String name)

Returns the enum constant of the specified enum type with the specified name. The name must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters
<T>
The enum type whose constant is to be returned
enumType:Class<T>

the Class object of the enum type from which to return a constant

name:String

the name of the constant to return

Returns:T

the enum constant of the specified enum type with the specified name

Exceptions
IllegalArgumentException:
if the specified enum type has no constant with the specified name, or the specified class object does not represent an enum type
NullPointerException:
if enumType or name are null
See Also
java.lang.Enum#valueOf(Class, String)
valuesback to summary
public static Level[] values()

Return an array of all the Levels that have been registered.

Returns:Level[]

An array of Levels.