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 any public APIs.
23 */
24 public enum StandardLevel {
25
26 /**
27 * No events will be logged.
28 */
29 OFF(0),
30
31 /**
32 * A severe error that will prevent the application from continuing.
33 */
34 FATAL(100),
35
36 /**
37 * An error in the application, possibly recoverable.
38 */
39 ERROR(200),
40
41 /**
42 * An event that might possible lead to an error.
43 */
44 WARN(300),
45
46 /**
47 * An event for informational purposes.
48 */
49 INFO(400),
50
51 /**
52 * A general debugging event.
53 */
54 DEBUG(500),
55
56 /**
57 * A fine-grained debug message, typically capturing the flow through the application.
58 */
59 TRACE(600),
60
61 /**
62 * All events should be logged.
63 */
64 ALL(Integer.MAX_VALUE);
65
66 private static final EnumSet<StandardLevel> LEVELSET = EnumSet.allOf(StandardLevel.class);
67
68 private final int intLevel;
69
70 StandardLevel(final int val) {
71 intLevel = val;
72 }
73
74 /**
75 * Returns the integer value of the Level.
76 *
77 * @return the integer value of the Level.
78 */
79 public int intLevel() {
80 return intLevel;
81 }
82
83 /**
84 * Method to convert custom Levels into a StandardLevel for conversion to other systems.
85 *
86 * @param intLevel The integer value of the Level.
87 * @return The StandardLevel.
88 */
89 public static StandardLevel getStandardLevel(final int intLevel) {
90 StandardLevel level = StandardLevel.OFF;
91 for (final StandardLevel lvl : LEVELSET) {
92 if (lvl.intLevel() > intLevel) {
93 break;
94 }
95 level = lvl;
96 }
97 return level;
98 }
99 }
100