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 * Numerical Severity<br> 25 * Code<br> 26 * 27 * 0 Emergency: system is unusable<br> 28 * 1 Alert: action must be taken immediately<br> 29 * 2 Critical: critical conditions<br> 30 * 3 Error: error conditions<br> 31 * 4 Warning: warning conditions<br> 32 * 5 Notice: normal but significant condition<br> 33 * 6 Informational: informational messages<br> 34 * 7 Debug: debug-level messages 35 */ 36 public enum Severity { 37 /** System is unusable. */ 38 EMERG(0), 39 /** Action must be taken immediately. */ 40 ALERT(1), 41 /** Critical conditions. */ 42 CRITICAL(2), 43 /** Error conditions. */ 44 ERROR(3), 45 /** Warning conditions. */ 46 WARNING(4), 47 /** Normal but significant conditions. */ 48 NOTICE(5), 49 /** Informational messages. */ 50 INFO(6), 51 /** Debug level messages. */ 52 DEBUG(7); 53 54 private final int code; 55 56 private Severity(int code) { 57 this.code = code; 58 } 59 60 /** 61 * Returns the severity code. 62 * @return The numeric value associated with the Severity. 63 */ 64 public int getCode() { 65 return this.code; 66 } 67 68 /** 69 * Determine if the name matches this Severity. 70 * @param name the name to match. 71 * @return true if the name matches, false otherwise. 72 */ 73 public boolean isEqual(String name) { 74 return this.name().equalsIgnoreCase(name); 75 } 76 77 /** 78 * Returns the Severity for the specified Level. 79 * @param level The Level. 80 * @return The matching Severity, or DEBUG if there is no match. 81 */ 82 public static Severity getSeverity(Level level) { 83 switch (level) { 84 case ALL: 85 return DEBUG; 86 case TRACE: 87 return DEBUG; 88 case DEBUG: 89 return DEBUG; 90 case INFO: 91 return INFO; 92 case WARN: 93 return WARNING; 94 case ERROR: 95 return ERROR; 96 case FATAL: 97 return ALERT; 98 case OFF: 99 return EMERG; 100 } 101 return DEBUG; 102 } 103 }