logging

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.

Ilias Tsagklis

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button