001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache license, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the license for the specific language governing permissions and
015 * limitations under the license.
016 */
017 package org.apache.logging.log4j.core.net;
018
019 import org.apache.logging.log4j.Level;
020
021 /**
022 * Severity values used by the Syslog system.
023 *
024 * <table summary="Syslog Severity Values">
025 * <tr>
026 * <th>Numerical Code</th>
027 * <th>Severity</th>
028 * </tr>
029 * <tr>
030 * <td>0</td>
031 * <td>Emergency: system is unusable</td>
032 * </tr>
033 * <tr>
034 * <td>1</td>
035 * <td>Alert: action must be taken immediately</td>
036 * </tr>
037 * <tr>
038 * <td>2</td>
039 * <td>Critical: critical conditions</td>
040 * </tr>
041 * <tr>
042 * <td>3</td>
043 * <td>Error: error conditions</td>
044 * </tr>
045 * <tr>
046 * <td>4</td>
047 * <td>Warning: warning conditions</td>
048 * </tr>
049 * <tr>
050 * <td>5</td>
051 * <td>Notice: normal but significant condition</td>
052 * </tr>
053 * <tr>
054 * <td>6</td>
055 * <td>Informational: informational messages</td>
056 * </tr>
057 * <tr>
058 * <td>7</td>
059 * <td>Debug: debug-level messages</td>
060 * </tr>
061 * </table>
062 */
063 public enum Severity {
064 /** System is unusable. */
065 EMERG(0),
066 /** Action must be taken immediately. */
067 ALERT(1),
068 /** Critical conditions. */
069 CRITICAL(2),
070 /** Error conditions. */
071 ERROR(3),
072 /** Warning conditions. */
073 WARNING(4),
074 /** Normal but significant conditions. */
075 NOTICE(5),
076 /** Informational messages. */
077 INFO(6),
078 /** Debug level messages. */
079 DEBUG(7);
080
081 private final int code;
082
083 private Severity(final int code) {
084 this.code = code;
085 }
086
087 /**
088 * Returns the severity code.
089 * @return The numeric value associated with the Severity.
090 */
091 public int getCode() {
092 return this.code;
093 }
094
095 /**
096 * Determine if the name matches this Severity.
097 * @param name the name to match.
098 * @return true if the name matches, false otherwise.
099 */
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 }