Home » Core Java » util » logging » Compare Logger Level

About Ilias Tsagklis

Ilias Tsagklis
Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.

Compare Logger Level

In this example we shall show you how to compare Logger Level. The logging Level is used to control logging output. Level objects, such as SEVERE, WARNING and INFO are ordered and specified by ordered integers, so in order to compare them, one should perform the following steps:

  • Use three Level constants.
  • Compare the intValues of each Level constant with the other ones, using the intValue() of the Level. The levels with bigger values than others are the ones that are the more severe,

as described in the code snippet below.
 

package com.javacodegeeks.snippets.core;

import java.util.logging.Level;
 
public class LogLevelComparison {
	
    public static void main(String[] args) {

  Level info = Level.INFO;

  Level warning = Level.WARNING;

  Level finest = Level.FINEST;
 

  // Compare the intValue of the Level

  if (info.intValue() < warning.intValue()) {


System.out.println(info + "(" + info.intValue() + ") is less severe than " +



  warning + "(" + warning.intValue() + ")");

  }
 

  if (finest.intValue() < info.intValue()) {


System.out.println(finest + "(" + finest.intValue() + ") is less severe than " +



  info + "(" + info.intValue()+ ")");

  }
    }
}

Output:

INFO(800) is less severe than WARNING(900)
FINEST(300) is less severe than INFO(800)

 
This was an example of how to compare Logger Level in Java.

(No Ratings Yet)
Start the discussion Views Tweet it!

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Leave a Reply

avatar
  Subscribe  
Notify of