Java Programing laungage

java.util Projects

java.util Project 1

Create a Custom Log Level

In This programming tutorials we are going to create a custom log level that means log levels are created by users for own need. Java logging class provides some levels like: WARNING, INFO, FINEST, SEVERE etc. See an example for the best description the procedure of creating a custom log level in Java application.

Previous Home Next
adplus-dvertising

Descriptions of program

This program is create a logger and the CustomLevel class extends to the Level class for constructing a custom log level. All levels have an unique value. Similarly, the custom log level has also an unique value which is retrieved by the intValue() method.

Descriptions of code

level.parse(String message)

This method takes string type value which has parsed into a level.

Example


package r4r;
import java.util.*;
import java.util.logging.*;
public class customloglevel extends Level {
protected customloglevel(String name, int value) {
super(name, value);
// TODO Auto-generated constructor stub
}
	/**
	 * 
	 */
private static final long serialVersionUID = 1L;
public static void main(String[] args) {
 Logger log = Logger.getLogger("R4RTechsoft.com");
 Level level1 = Level.WARNING;
 int num = level1.intValue();
 Level level = new customloglevel("R4R Level", num);
 Level clevel = level.parse("R4R Level");
 log.log(clevel, "It is Custom Level");
 }
 public void CustomLevel(String str, int val){
 super(str, val);
 }
}

Previous Home Next