View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements. See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache license, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License. You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the license for the specific language governing permissions and
15   * limitations under the license.
16   */
17  package org.apache.logging.log4j.spi;
18  
19  import java.util.EnumSet;
20  
21  /**
22   * Standard Logging Levels as an enumeration for use internally. This enum is used as a parameter in
23   * any public APIs.
24   */
25  public enum StandardLevel {
26  
27      /**
28       * No events will be logged.
29       */
30      OFF(0),
31  
32      /**
33       * A severe error that will prevent the application from continuing.
34       */
35      FATAL(100),
36  
37      /**
38       * An error in the application, possibly recoverable.
39       */
40      ERROR(200),
41  
42      /**
43       * An event that might possible lead to an error.
44       */
45      WARN(300),
46  
47      /**
48       * An event for informational purposes.
49       */
50      INFO(400),
51  
52      /**
53       * A general debugging event.
54       */
55      DEBUG(500),
56  
57      /**
58       * A fine-grained debug message, typically capturing the flow through the application.
59       */
60      TRACE(600),
61  
62      /**
63       * All events should be logged.
64       */
65      ALL(Integer.MAX_VALUE);
66  
67  
68      private final int intLevel;
69  
70      private static final EnumSet<StandardLevel> levelSet = EnumSet.allOf(StandardLevel.class);
71  
72      private StandardLevel(final int val) {
73          intLevel = val;
74      }
75  
76      /**
77       * Returns the integer value of the Level.
78       * @return the integer value of the Level.
79       */
80      public int intLevel() {
81          return intLevel;
82      }
83  
84      /**
85       * Method to convert custom Levels into a StandardLevel for conversion to other systems.
86       * @param intLevel The integer value of the Level.
87       * @return The StandardLevel.
88       */
89      public static StandardLevel getStandardLevel(int intLevel) {
90          StandardLevel level = StandardLevel.OFF;
91          for (StandardLevel lvl : levelSet) {
92              if (lvl.intLevel() > intLevel) {
93                  break;
94              }
95              level = lvl;
96          }
97          return level;
98      }
99  }