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.util.EnglishEnums; 020 021/** 022 * The facility codes used by the Syslog system. 023 * 024 * <table> 025 * <tr> 026 * <th>Numerical Code</th> 027 * <th>Facility</th> 028 * </tr> 029 * <tr> 030 * <td>0</td> 031 * <td>kernel messages</td> 032 * </tr> 033 * <tr> 034 * <td>1</td> 035 * <td>user-level messages</td> 036 * </tr> 037 * <tr> 038 * <td>2</td> 039 * <td>mail system</td> 040 * </tr> 041 * <tr> 042 * <td>3</td> 043 * <td>system daemons</td> 044 * </tr> 045 * <tr> 046 * <td>4</td> 047 * <td>security/authorization messages</td> 048 * </tr> 049 * <tr> 050 * <td>5</td> 051 * <td>messages generated internally by syslogd</td> 052 * </tr> 053 * <tr> 054 * <td>6</td> 055 * <td>line printer subsystem</td> 056 * </tr> 057 * <tr> 058 * <td>7</td> 059 * <td>network news subsystem</td> 060 * </tr> 061 * <tr> 062 * <td>8</td> 063 * <td>UUCP subsystem</td> 064 * </tr> 065 * <tr> 066 * <td>9</td> 067 * <td>clock daemon</td> 068 * </tr> 069 * <tr> 070 * <td>10</td> 071 * <td>security/authorization messages</td> 072 * </tr> 073 * <tr> 074 * <td>11</td> 075 * <td>FTP daemon</td> 076 * </tr> 077 * <tr> 078 * <td>12</td> 079 * <td>NTP subsystem</td> 080 * </tr> 081 * <tr> 082 * <td>13</td> 083 * <td>log audit</td> 084 * </tr> 085 * <tr> 086 * <td>14</td> 087 * <td>log alert</td> 088 * </tr> 089 * <tr> 090 * <td>15</td> 091 * <td>clock daemon (note 2)</td> 092 * </tr> 093 * <tr> 094 * <td>16</td> 095 * <td>local use 0 (local0)</td> 096 * </tr> 097 * <tr> 098 * <td>17</td> 099 * <td>local use 1 (local1)</td> 100 * </tr> 101 * <tr> 102 * <td>18</td> 103 * <td>local use 2 (local2)</td> 104 * </tr> 105 * <tr> 106 * <td>19</td> 107 * <td>local use 3 (local3)</td> 108 * </tr> 109 * <tr> 110 * <td>20</td> 111 * <td>local use 4 (local4)</td> 112 * </tr> 113 * <tr> 114 * <td>21</td> 115 * <td>local use 5 (local5)</td> 116 * </tr> 117 * <tr> 118 * <td>22</td> 119 * <td>local use 6 (local6)</td> 120 * </tr> 121 * <tr> 122 * <td>23</td> 123 * <td>local use 7 (local7)</td> 124 * </tr> 125 * </table> 126 */ 127public enum Facility { 128 /** Kernel messages. */ 129 KERN(0), 130 /** User level messages. */ 131 USER(1), 132 /** Mail system. */ 133 MAIL(2), 134 /** System daemons. */ 135 DAEMON(3), 136 /** Security/Authorization messages. */ 137 AUTH(4), 138 /** Messages generated by syslogd. */ 139 SYSLOG(5), 140 /** Line printer subsystem. */ 141 LPR(6), 142 /** Network news subsystem. */ 143 NEWS(7), 144 /** UUCP subsystem. */ 145 UUCP(8), 146 /** Clock daemon. */ 147 CRON(9), 148 /** Security/Authorization messages. */ 149 AUTHPRIV(10), 150 /** FTP daemon. */ 151 FTP(11), 152 /** NTP subsystem. */ 153 NTP(12), 154 /** Log audit. */ 155 LOG_AUDIT(13), 156 /** Log alert. */ 157 LOG_ALERT(14), 158 /** Clock daemon. */ 159 CLOCK(15), 160 /** Local use 0. */ 161 LOCAL0(16), 162 /** Local use 1. */ 163 LOCAL1(17), 164 /** Local use 2. */ 165 LOCAL2(18), 166 /** Local use 3. */ 167 LOCAL3(19), 168 /** Local use 4. */ 169 LOCAL4(20), 170 /** Local use 5. */ 171 LOCAL5(21), 172 /** Local use 6. */ 173 LOCAL6(22), 174 /** Local use 7. */ 175 LOCAL7(23); 176 177 private final int code; 178 179 Facility(final int code) { 180 this.code = code; 181 } 182 183 /** 184 * Returns the Facility for the given string. 185 * 186 * @param name The Facility enum name, case-insensitive. If null, returns, null 187 * @return a Facility enum value or null if name is null 188 */ 189 public static Facility toFacility(final String name) { 190 return toFacility(name, null); 191 } 192 193 /** 194 * Returns the Facility for the given string. 195 * 196 * @param name The Facility enum name, case-insensitive. If null, returns, defaultFacility 197 * @param defaultFacility the Facility to return if name is null 198 * @return a Facility enum value or null if name is null 199 */ 200 public static Facility toFacility(final String name, final Facility defaultFacility) { 201 return EnglishEnums.valueOf(Facility.class, name, defaultFacility); 202 } 203 204 /** 205 * Retrieve the value of the enumeration. 206 * @return The value associated with the enumeration. 207 */ 208 public int getCode() { 209 return this.code; 210 } 211 212 /** 213 * Determine if this enumeration matches the specified name (ignoring case). 214 * @param name The name to check. 215 * @return true if the name matches this enumeration, ignoring case. 216 */ 217 public boolean isEqual(final String name) { 218 return this.name().equalsIgnoreCase(name); 219 } 220 221}