Java Programing laungage

java.util Projects

java.util Project 1

Access Log Levels of a Logger

In This programming tutorials, we are going to access to the log level of the Logger through the java program and Described it how to get it. The Logger is used for provides many types of levels of a logger like: WARNING, INFO, SEVERE and FINEST etc.

Previous Home Next

In this programming section, We gave an example for the best description of the topic. In the following program, an object of the LogRecord class is created with the log level and the log message or information for the specific log record. And the last thing is getting the log level and display it in the console.

code Description

LogRecord rec1 = new LogRecord(Level.WARNING, "Do something here!")

This code is used to creates an object of the LogRecord class with specifying log level and the information for the logger.

LogRecord.getLevel()

This method is used to return us the level of the log record and for the specific object of the LogRecord class.

Example


package r4r;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.LogRecord;
public class accesslogleveltest {
	
public static void main(String[] args) {
LogRecord rec1 = new LogRecord(Level.WARNING,"It is warning Level!");
System.out.println(rec1.getLevel());
LogRecord rec2 = new LogRecord(Level.INFO,"It is info Level!");
System.out.println(rec2.getLevel());
LogRecord rec3 = new LogRecord(Level.SEVERE,"It is severe Level!");
System.out.println(rec3.getLevel());
}
}

Previous Home Next