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 */ 017package org.apache.logging.log4j.core.net; 018 019import org.apache.logging.log4j.Level; 020 021/** 022 * Severity values used by the Syslog system. 023 * 024 * Numerical Severity<br> 025 * Code<br> 026 * 027 * 0 Emergency: system is unusable<br> 028 * 1 Alert: action must be taken immediately<br> 029 * 2 Critical: critical conditions<br> 030 * 3 Error: error conditions<br> 031 * 4 Warning: warning conditions<br> 032 * 5 Notice: normal but significant condition<br> 033 * 6 Informational: informational messages<br> 034 * 7 Debug: debug-level messages 035 */ 036public enum Severity { 037 /** System is unusable. */ 038 EMERG(0), 039 /** Action must be taken immediately. */ 040 ALERT(1), 041 /** Critical conditions. */ 042 CRITICAL(2), 043 /** Error conditions. */ 044 ERROR(3), 045 /** Warning conditions. */ 046 WARNING(4), 047 /** Normal but significant conditions. */ 048 NOTICE(5), 049 /** Informational messages. */ 050 INFO(6), 051 /** Debug level messages. */ 052 DEBUG(7); 053 054 private final int code; 055 056 private Severity(final int code) { 057 this.code = code; 058 } 059 060 /** 061 * Returns the severity code. 062 * @return The numeric value associated with the Severity. 063 */ 064 public int getCode() { 065 return this.code; 066 } 067 068 /** 069 * Determine if the name matches this Severity. 070 * @param name the name to match. 071 * @return true if the name matches, false otherwise. 072 */ 073 public boolean isEqual(final String name) { 074 return this.name().equalsIgnoreCase(name); 075 } 076 077 /** 078 * Returns the Severity for the specified Level. 079 * @param level The Level. 080 * @return The matching Severity, or DEBUG if there is no match. 081 */ 082 public static Severity getSeverity(final Level level) { 083 switch (level.getStandardLevel()) { 084 case ALL: 085 return DEBUG; 086 case TRACE: 087 return DEBUG; 088 case DEBUG: 089 return DEBUG; 090 case INFO: 091 return INFO; 092 case WARN: 093 return WARNING; 094 case ERROR: 095 return ERROR; 096 case FATAL: 097 return ALERT; 098 case OFF: 099 return EMERG; 100 } 101 return DEBUG; 102 } 103}