Use different logging level : Log Level « Log « Java Tutorial






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

public class MainClass {

  private static Logger
    lgr = Logger.getLogger("com"),
    lgr2 = Logger.getLogger("com.java2s"),
    util = Logger.getLogger("com.java2s.util"),
    test = Logger.getLogger("com.java2s.test"),
    rand = Logger.getLogger("random");
    
  private static void logMessages() {
    lgr.info("com : info");
    lgr2.info("com.bruceeckel : info");
    util.info("util : info");
    test.severe("test : severe");
    rand.info("random : info");
  }
  public static void main(String[] args) {
    lgr.setLevel(Level.SEVERE);
    System.out.println("com level: SEVERE");
    logMessages();
    util.setLevel(Level.FINEST);
    test.setLevel(Level.FINEST);
    rand.setLevel(Level.FINEST);
    System.out.println("individual loggers set to FINEST");
    logMessages();
    lgr.setLevel(Level.SEVERE);
    System.out.println("com level: SEVERE");
    logMessages();

  }
}








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().