Java如何比较记录器级别的严重性?

在此示例中,我们看到了如何比较Level两个级别之间的严重性。的Level类有一个intValue()返回的整数值的方法Level的严重程度。

package org.nhooo.example.util.logging;

import java.util.logging.Level;

public class LogLevelSeverityCompare {
    public static void main(String[] args) {
        Level info = Level.INFO;
        Level warning = Level.WARNING;
        Level finest = Level.FINEST;

        // 为了比较级别的严重性,我们比较级别的intValue。
        // 每个级别分配一个唯一的整数值作为严重性
        // 水平的重量。
        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()+ ")");
        }
    }
}

当我们运行上面的程序时,将看到以下结果:

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