001/*
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2024, 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 */
014
015package ch.qos.logback.classic.util;
016
017import ch.qos.logback.classic.Level;
018import ch.qos.logback.core.joran.JoranConstants;
019import ch.qos.logback.core.util.OptionHelper;
020
021import static ch.qos.logback.core.joran.JoranConstants.NULL;
022
023/**
024 *
025 * Utility methods for transforming string values to Level.
026 *
027 * @since 1.5.1
028 */
029public class LevelUtil {
030
031
032    public static boolean isInheritedLevelString(String levelStr) {
033        if (JoranConstants.INHERITED.equalsIgnoreCase(levelStr) || NULL.equalsIgnoreCase(levelStr)) {
034            return true;
035        } else
036            return false;
037    }
038
039    public static Level levelStringToLevel(String levelStr) {
040        if (!OptionHelper.isNullOrEmptyOrAllSpaces(levelStr)) {
041            if (isInheritedLevelString(levelStr)) {
042                return null;
043            } else {
044                Level level = Level.toLevel(levelStr);
045                return level;
046            }
047        }
048        return null;
049    }
050
051}