001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.classic.jul;
015
016import ch.qos.logback.classic.Level;
017import ch.qos.logback.classic.Logger;
018
019public class JULHelper {
020
021    static public final boolean isRegularNonRootLogger(java.util.logging.Logger julLogger) {
022        if (julLogger == null)
023            return false;
024        return !julLogger.getName().equals("");
025    }
026
027    static public final boolean isRoot(java.util.logging.Logger julLogger) {
028        if (julLogger == null)
029            return false;
030        return julLogger.getName().equals("");
031    }
032
033    static public java.util.logging.Level asJULLevel(Level lbLevel) {
034        if (lbLevel == null)
035            throw new IllegalArgumentException("Unexpected level [null]");
036
037        switch (lbLevel.levelInt) {
038        case Level.ALL_INT:
039            return java.util.logging.Level.ALL;
040        case Level.TRACE_INT:
041            return java.util.logging.Level.FINEST;
042        case Level.DEBUG_INT:
043            return java.util.logging.Level.FINE;
044        case Level.INFO_INT:
045            return java.util.logging.Level.INFO;
046        case Level.WARN_INT:
047            return java.util.logging.Level.WARNING;
048        case Level.ERROR_INT:
049            return java.util.logging.Level.SEVERE;
050        case Level.OFF_INT:
051            return java.util.logging.Level.OFF;
052        default:
053            throw new IllegalArgumentException("Unexpected level [" + lbLevel + "]");
054        }
055    }
056
057    static public String asJULLoggerName(String loggerName) {
058        if (Logger.ROOT_LOGGER_NAME.equals(loggerName))
059            return "";
060        else
061            return loggerName;
062    }
063
064    static public java.util.logging.Logger asJULLogger(String loggerName) {
065        String julLoggerName = asJULLoggerName(loggerName);
066        return java.util.logging.Logger.getLogger(julLoggerName);
067    }
068
069    static public java.util.logging.Logger asJULLogger(Logger logger) {
070        return asJULLogger(logger.getName());
071    }
072
073}