View Javadoc

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   *        Numerical          Facility<br>
25   *           Code<br>
26   *
27   *             0             kernel messages<br>
28   *             1             user-level messages<br>
29   *             2             mail system<br>
30   *             3             system daemons<br>
31   *             4             security/authorization messages<br>
32   *             5             messages generated internally by syslogd<br>
33   *             6             line printer subsystem<br>
34   *             7             network news subsystem<br>
35   *             8             UUCP subsystem<br>
36   *             9             clock daemon<br>
37   *            10             security/authorization messages<br>
38   *            11             FTP daemon<br>
39   *            12             NTP subsystem<br>
40   *            13             log audit<br>
41   *            14             log alert<br>
42   *            15             clock daemon (note 2)<br>
43   *            16             local use 0  (local0)<br>
44   *            17             local use 1  (local1)<br>
45   *            18             local use 2  (local2)<br>
46   *            19             local use 3  (local3)<br>
47   *            20             local use 4  (local4)<br>
48   *            21             local use 5  (local5)<br>
49   *            22             local use 6  (local6)<br>
50   *            23             local use 7  (local7)<br>
51   */
52  public enum Facility {
53      /** Kernel messages. */
54      KERN(0),
55      /** User level messages. */
56      USER(1),
57      /** Mail system. */
58      MAIL(2),
59      /** System daemons. */
60      DAEMON(3),
61      /** Security/Authorization messages. */
62      AUTH(4),
63      /** Messages generated by syslogd. */
64      SYSLOG(5),
65      /** Line printer subsystem. */
66      LPR(6),
67      /** Network news subsystem. */
68      NEWS(7),
69      /** UUCP subsystem. */
70      UUCP(8),
71      /** Clock daemon. */
72      CRON(9),
73      /** Security/Authorization messages. */
74      AUTHPRIV(10),
75      /** FTP daemon. */
76      FTP(11),
77      /** NTP subsystem. */
78      NTP(12),
79      /** Log audit. */
80      LOG_AUDIT(13),
81      /** Log alert. */
82      LOG_ALERT(14),
83      /** Clock daemon. */
84      CLOCK(15),
85      /** Local use 0. */
86      LOCAL0(16),
87      /** Local use 1. */
88      LOCAL1(17),
89      /** Local use 2. */
90      LOCAL2(18),
91      /** Local use 3. */
92      LOCAL3(19),
93      /** Local use 4. */
94      LOCAL4(20),
95      /** Local use 5. */
96      LOCAL5(21),
97      /** Local use 6. */
98      LOCAL6(22),
99      /** Local use 7. */
100     LOCAL7(23);
101 
102     private final int code;
103 
104     private Facility(final int code) {
105         this.code = code;
106     }
107 
108     /**
109      * Returns the Facility for the given string.
110      *
111      * @param name The Facility enum name, case-insensitive. If null, returns, null
112      * @return a Facility enum value or null if name is null
113      */
114     public static Facility toFacility(final String name) {
115         return toFacility(name, null);
116     }
117 
118     /**
119      * Returns the Facility for the given string.
120      *
121      * @param name The Facility enum name, case-insensitive. If null, returns, defaultFacility
122      * @param defaultFacility the Facility to return if name is null
123      * @return a Facility enum value or null if name is null
124      */
125     public static Facility toFacility(final String name, final Facility defaultFacility) {
126         return EnglishEnums.valueOf(Facility.class, name, defaultFacility);
127     }
128 
129     /**
130      * Retrieve the value of the enumeration.
131      * @return The value associated with the enumeration.
132      */
133     public int getCode() {
134         return this.code;
135     }
136 
137     /**
138      * Determine if this enumeration matches the specified name (ignoring case).
139      * @param name The name to check.
140      * @return true if the name matches this enumeration, ignoring case.
141      */
142     public boolean isEqual(final String name) {
143         return this.name().equalsIgnoreCase(name);
144     }
145 
146 }