Home Java Example Java Util Getting the Log Level of a Logger



Getting the Log Level of a Logger
Posted on: February 22, 2008 at 12:00 AM
This section helps you to learn about the getting log level of a logger through the java program and illustrates how to get it.

Getting the Log Level of a Logger

     

This section helps you to learn about the getting log level of a logger through the java program and illustrates how to get it. The Logger provides various types of levels of a logger like: INFO, WARNING, SEVERE and FINEST etc.

In this section, an example is provided for the best illustration of the topic. In the following program, a object of the LogRecord class is created with the log level and the log message for the specific log record. And the last thing is getting log level and display it in the console.

Description of code:

LogRecord rec1 = new  LogRecord(Level.WARNING, "Do something here!"):
Above code creates an object of the LogRecord class with specifying log level and the message for the logger.

LogRecord.getLevel():
This method gives you the level of the log record and for the specific object of the LogRecord class.

Here is the code of program:

import java.util.logging.*;

public class GetLogLevel{
  public static void main(String[] args) {
  LogRecord rec1 = new LogRecord(Level.WARNING,"Do something here!");
  System.out.println(rec1.getLevel());
  LogRecord rec2 = new LogRecord(Level.INFO,"Do something here!");
  System.out.println(rec2.getLevel());
  LogRecord rec3 = new LogRecord(Level.SEVERE,"Do something here!");
  System.out.println(rec3.getLevel());
  }
}

Download this example.

Output:

C:\java\logging>java GetLogLevel
WARNING
INFO
SEVERE

Related Tags for Getting the Log Level of a Logger:
javacideclassconsoleobjectiotypeshelpgettypedisplayviolethismessageidlogwarcreatelikewarningifforexamplerecordwithprogramtolearnramexamloggerpicciasttopeareilitlastdessectionlslisplvarpeininfolevelasmoutplaypstrsagethinoggoggjispclesspecthroughagepilevelsmehowillustrationhrobjprorateratesxaxampsssaspsocreatedessatratiokisinfllmplgrefolloweaandarconsstrspecificsawingvavariousttssrirdthavbesstabatidispetcfinetcjepleplprndonogrolo


More Tutorials from this section

Ask Questions?    Discuss: Getting the Log Level of a Logger  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.