logging

Compare Logger Level

Photo of Ilias TsagklisIlias TsagklisNovember 11th, 2012Last Updated: May 16th, 2013
0 133 1 minute read

In this example we shall show you how to compareLoggerLevel. 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 threeLevel constants.
  • Compare theintValues of each Level constant with the other ones, using theintValue() 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.

Do you want to know how to develop your skillset to become aJava Rockstar?
Subscribe to our newsletter to start Rockingright now!
To get you started we give you our best selling eBooks forFREE!
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 ....
I agree to theTerms andPrivacy Policy

Thank you!

We will contact you soon.

Photo of Ilias TsagklisIlias TsagklisNovember 11th, 2012Last Updated: May 16th, 2013
0 133 1 minute read
Photo of Ilias Tsagklis

Ilias Tsagklis

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

Related Articles

Bipartite Graph

Conditional logging

November 11th, 2012
Bipartite Graph

Log method call

November 11th, 2012
Bipartite Graph

Set logger log level

November 11th, 2012
Subscribe
Notify of
guest
I agree to theTerms andPrivacy Policy
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.

I agree to theTerms andPrivacy Policy
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.