Monday, March 28, 2016

Java Logging Examples : How To Compare Log Level Severity

Intro


This examples will demonstrates how to compare log level severity for each log level. The java.util.logging.Level class has an intValue() method that return the integer value of Level‘s severity.

Examples


package com.freesamplecode.java.logging;

import java.util.logging.Level;

public class CompareLogLevelSeverityDemo {
 public static void main(String[] args){
  Level info = Level.INFO;
        Level warning = Level.WARNING;
        Level config = Level.CONFIG;
        Level finest = Level.FINEST;
        
        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()+ ")");
        }
        
        if (config.intValue() < warning.intValue()) {
            System.out.println(config + "(" + config.intValue() + ") is less severe than " +
                    warning + "(" + warning.intValue()+ ")");
        }
 }
}

Output


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

Screenshot


How To Compare Log Level Severity In Java


Related Posts:

0 comments: