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
129 /** Kernel messages. */
130 KERN(0),
131
132 /** User level messages. */
133 USER(1),
134
135 /** Mail system. */
136 MAIL(2),
137
138 /** System daemons. */
139 DAEMON(3),
140
141 /** Security/Authorization messages. */
142 AUTH(4),
143
144 /** Messages generated by syslogd. */
145 SYSLOG(5),
146
147 /** Line printer subsystem. */
148 LPR(6),
149
150 /** Network news subsystem. */
151 NEWS(7),
152
153 /** UUCP subsystem. */
154 UUCP(8),
155
156 /** Clock daemon. */
157 CRON(9),
158
159 /** Security/Authorization messages. */
160 AUTHPRIV(10),
161
162 /** FTP daemon. */
163 FTP(11),
164
165 /** NTP subsystem. */
166 NTP(12),
167
168 /** Log audit. */
169 LOG_AUDIT(13),
170
171 /** Log alert. */
172 LOG_ALERT(14),
173
174 /** Clock daemon. */
175 CLOCK(15),
176
177 /** Local use 0. */
178 LOCAL0(16),
179
180 /** Local use 1. */
181 LOCAL1(17),
182
183 /** Local use 2. */
184 LOCAL2(18),
185
186 /** Local use 3. */
187 LOCAL3(19),
188
189 /** Local use 4. */
190 LOCAL4(20),
191
192 /** Local use 5. */
193 LOCAL5(21),
194
195 /** Local use 6. */
196 LOCAL6(22),
197
198 /** Local use 7. */
199 LOCAL7(23);
200
201 private final int code;
202
203 Facility(final int code) {
204 this.code = code;
205 }
206
207 /**
208 * Returns the Facility for the given string.
209 *
210 * @param name The Facility enum name, case-insensitive. If null, returns, null
211 * @return a Facility enum value or null if name is null
212 */
213 public static Facility toFacility(final String name) {
214 return toFacility(name, null);
215 }
216
217 /**
218 * Returns the Facility for the given string.
219 *
220 * @param name The Facility enum name, case-insensitive. If null, returns, defaultFacility
221 * @param defaultFacility the Facility to return if name is null
222 * @return a Facility enum value or null if name is null
223 */
224 public static Facility toFacility(final String name, final Facility defaultFacility) {
225 return EnglishEnums.valueOf(Facility.class, name, defaultFacility);
226 }
227
228 /**
229 * Retrieve the value of the enumeration.
230 * @return The value associated with the enumeration.
231 */
232 public int getCode() {
233 return this.code;
234 }
235
236 /**
237 * Determine if this enumeration matches the specified name (ignoring case).
238 * @param name The name to check.
239 * @return true if the name matches this enumeration, ignoring case.
240 */
241 public boolean isEqual(final String name) {
242 return this.name().equalsIgnoreCase(name);
243 }
244
245 }