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    
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}