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.util.EnglishEnums; 20 21 /** 22 * The facility codes used by the Syslog system. 23 * 24 * <table> 25 * <tr> 26 * <th>Numerical Code</th> 27 * <th>Facility</th> 28 * </tr> 29 * <tr> 30 * <td>0</td> 31 * <td>kernel messages</td> 32 * </tr> 33 * <tr> 34 * <td>1</td> 35 * <td>user-level messages</td> 36 * </tr> 37 * <tr> 38 * <td>2</td> 39 * <td>mail system</td> 40 * </tr> 41 * <tr> 42 * <td>3</td> 43 * <td>system daemons</td> 44 * </tr> 45 * <tr> 46 * <td>4</td> 47 * <td>security/authorization messages</td> 48 * </tr> 49 * <tr> 50 * <td>5</td> 51 * <td>messages generated internally by syslogd</td> 52 * </tr> 53 * <tr> 54 * <td>6</td> 55 * <td>line printer subsystem</td> 56 * </tr> 57 * <tr> 58 * <td>7</td> 59 * <td>network news subsystem</td> 60 * </tr> 61 * <tr> 62 * <td>8</td> 63 * <td>UUCP subsystem</td> 64 * </tr> 65 * <tr> 66 * <td>9</td> 67 * <td>clock daemon</td> 68 * </tr> 69 * <tr> 70 * <td>10</td> 71 * <td>security/authorization messages</td> 72 * </tr> 73 * <tr> 74 * <td>11</td> 75 * <td>FTP daemon</td> 76 * </tr> 77 * <tr> 78 * <td>12</td> 79 * <td>NTP subsystem</td> 80 * </tr> 81 * <tr> 82 * <td>13</td> 83 * <td>log audit</td> 84 * </tr> 85 * <tr> 86 * <td>14</td> 87 * <td>log alert</td> 88 * </tr> 89 * <tr> 90 * <td>15</td> 91 * <td>clock daemon (note 2)</td> 92 * </tr> 93 * <tr> 94 * <td>16</td> 95 * <td>local use 0 (local0)</td> 96 * </tr> 97 * <tr> 98 * <td>17</td> 99 * <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 */ 127 public 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 }