In this example we see how we can compare the Level
severity between two levels. The Level
class has an intValue()
method that return the integer value of Level
‘s severity.
package org.kodejava.util.logging;
import java.util.logging.Level;
public class LogLevelSeverityCompare {
public static void main(String[] args) {
Level info = Level.INFO;
Level warning = Level.WARNING;
Level finest = Level.FINEST;
// To compare the Level severity we compare the intValue of the Level.
// Each level is assigned a unique integer value as the severity
// weight of the level.
if (info.intValue() < warning.intValue()) {
System.out.printf("%s (%d) is less severe than %s (%d)%n",
info, info.intValue(), warning, warning.intValue());
}
if (finest.intValue() < info.intValue()) {
System.out.printf("%s (%d) is less severe than %s (%d)%n",
finest, finest.intValue(), info, info.intValue());
}
}
}
When we run the program above will see the following result:
INFO (800) is less severe than WARNING (900)
FINEST (300) is less severe than INFO (800)