Creating a Custom Log Level : Log Level « Log « Java Tutorial






import java.util.logging.Level;
import java.util.logging.Logger;

class MyLevel extends Level {
  public static final Level DISASTER = new MyLevel("DISASTER", Level.SEVERE.intValue() + 1);

  public MyLevel(String name, int value) {
    super(name, value);
  }
}

public class Main {
  public static void main(String[] argv) throws Exception {
    Logger logger = Logger.getLogger("com.mycompany");
    logger.log(MyLevel.DISASTER, "my disaster message");

    Level disaster = Level.parse("DISASTER");
    logger.log(disaster, "my disaster message");
  }
}








35.2.Log Level
35.2.1.Use different logging level
35.2.2.Setting the Log Level of a Logger
35.2.3.Getting the Log Level of a Logger
35.2.4.Creating a Custom Log Level
35.2.5.Log finest, finer, config, warning ans severe
35.2.6.Determining If a Message Will Be Logged
35.2.7.Comparing Log Levels: To compare the severity of two logging levels, use Level.intValue().