1   /*
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2024, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  
15  package ch.qos.logback.classic.util;
16  
17  import ch.qos.logback.classic.Level;
18  import ch.qos.logback.core.joran.JoranConstants;
19  import ch.qos.logback.core.util.OptionHelper;
20  
21  import static ch.qos.logback.core.joran.JoranConstants.NULL;
22  
23  /**
24   *
25   * Utility methods for transforming string values to Level.
26   *
27   * @since 1.5.1
28   */
29  public class LevelUtil {
30  
31  
32      public static boolean isInheritedLevelString(String levelStr) {
33          if (JoranConstants.INHERITED.equalsIgnoreCase(levelStr) || NULL.equalsIgnoreCase(levelStr)) {
34              return true;
35          } else
36              return false;
37      }
38  
39      public static Level levelStringToLevel(String levelStr) {
40          if (!OptionHelper.isNullOrEmptyOrAllSpaces(levelStr)) {
41              if (isInheritedLevelString(levelStr)) {
42                  return null;
43              } else {
44                  Level level = Level.toLevel(levelStr);
45                  return level;
46              }
47          }
48          return null;
49      }
50  
51  }