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.core.net;
18
19 import org.apache.logging.log4j.Level;
20
21 /**
22 * Severity values used by the Syslog system.
23 *
24 * <table summary="Syslog Severity Values">
25 * <tr>
26 * <th>Numerical Code</th>
27 * <th>Severity</th>
28 * </tr>
29 * <tr>
30 * <td>0</td>
31 * <td>Emergency: system is unusable</td>
32 * </tr>
33 * <tr>
34 * <td>1</td>
35 * <td>Alert: action must be taken immediately</td>
36 * </tr>
37 * <tr>
38 * <td>2</td>
39 * <td>Critical: critical conditions</td>
40 * </tr>
41 * <tr>
42 * <td>3</td>
43 * <td>Error: error conditions</td>
44 * </tr>
45 * <tr>
46 * <td>4</td>
47 * <td>Warning: warning conditions</td>
48 * </tr>
49 * <tr>
50 * <td>5</td>
51 * <td>Notice: normal but significant condition</td>
52 * </tr>
53 * <tr>
54 * <td>6</td>
55 * <td>Informational: informational messages</td>
56 * </tr>
57 * <tr>
58 * <td>7</td>
59 * <td>Debug: debug-level messages</td>
60 * </tr>
61 * </table>
62 */
63 public enum Severity {
64 /** System is unusable. */
65 EMERG(0),
66 /** Action must be taken immediately. */
67 ALERT(1),
68 /** Critical conditions. */
69 CRITICAL(2),
70 /** Error conditions. */
71 ERROR(3),
72 /** Warning conditions. */
73 WARNING(4),
74 /** Normal but significant conditions. */
75 NOTICE(5),
76 /** Informational messages. */
77 INFO(6),
78 /** Debug level messages. */
79 DEBUG(7);
80
81 private final int code;
82
83 private Severity(final int code) {
84 this.code = code;
85 }
86
87 /**
88 * Returns the severity code.
89 * @return The numeric value associated with the Severity.
90 */
91 public int getCode() {
92 return this.code;
93 }
94
95 /**
96 * Determine if the name matches this Severity.
97 * @param name the name to match.
98 * @return true if the name matches, false otherwise.
99 */
100 public boolean isEqual(final String name) {
101 return this.name().equalsIgnoreCase(name);
102 }
103
104 /**
105 * Returns the Severity for the specified Level.
106 * @param level The Level.
107 * @return The matching Severity, or DEBUG if there is no match.
108 */
109 public static Severity getSeverity(final Level level) {
110 switch (level.getStandardLevel()) {
111 case ALL:
112 return DEBUG;
113 case TRACE:
114 return DEBUG;
115 case DEBUG:
116 return DEBUG;
117 case INFO:
118 return INFO;
119 case WARN:
120 return WARNING;
121 case ERROR:
122 return ERROR;
123 case FATAL:
124 return ALERT;
125 case OFF:
126 return EMERG;
127 }
128 return DEBUG;
129 }
130 }