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.Level;
20  
21  /**
22   * The Priority used in the Syslog system. Calculated from the Facility and Severity values.
23   */
24  public class Priority {
25  
26      private final Facility facility;
27      private final Severity severity;
28  
29      /**
30       * The Constructor.
31       * @param facility The Facility.
32       * @param severity The Severity.
33       */
34      public Priority(final Facility facility, final Severity severity) {
35          this.facility = facility;
36          this.severity = severity;
37      }
38  
39      /**
40       * Returns the priority value based on the Facility and Log Level.
41       * @param facility The Facility.
42       * @param level The Level.
43       * @return The integer value of the priority.
44       */
45      public static int getPriority(final Facility facility, final Level level) {
46          return (facility.getCode() << 3) + Severity.getSeverity(level).getCode();
47      }
48  
49      /**
50       * Returns the Facility.
51       * @return the Facility.
52       */
53      public Facility getFacility() {
54          return facility;
55      }
56  
57      /**
58       * Returns the Severity.
59       * @return the Severity.
60       */
61      public Severity getSeverity() {
62          return severity;
63      }
64  
65      /**
66       * Returns the value of this Priority.
67       * @return the value of this Priority.
68       */
69      public int getValue() {
70          return facility.getCode() << 3 + severity.getCode();
71      }
72  
73      @Override
74      public String toString() {
75          return Integer.toString(getValue());
76      }
77  }