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 toPriority(facility, Severity.getSeverity(level));
47 }
48
49 private static int toPriority(Facility aFacility, Severity aSeverity) {
50 return (aFacility.getCode() << 3) + aSeverity.getCode();
51 }
52
53 /**
54 * Returns the Facility.
55 * @return the Facility.
56 */
57 public Facility getFacility() {
58 return facility;
59 }
60
61 /**
62 * Returns the Severity.
63 * @return the Severity.
64 */
65 public Severity getSeverity() {
66 return severity;
67 }
68
69 /**
70 * Returns the value of this Priority.
71 * @return the value of this Priority.
72 */
73 public int getValue() {
74 return toPriority(facility, severity);
75 }
76
77 @Override
78 public String toString() {
79 return Integer.toString(getValue());
80 }
81 }