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 */ 017 package org.apache.logging.log4j.core.net; 018 019 import org.apache.logging.log4j.Level; 020 021 /** 022 * The Priority used in the Syslog system. Calculated from the Facility and Severity values. 023 */ 024 public class Priority { 025 026 private final Facility facility; 027 private final Severity severity; 028 029 /** 030 * The Constructor. 031 * @param facility The Facility. 032 * @param severity The Severity. 033 */ 034 public Priority(final Facility facility, final Severity severity) { 035 this.facility = facility; 036 this.severity = severity; 037 } 038 039 /** 040 * Returns the priority value based on the Facility and Log Level. 041 * @param facility The Facility. 042 * @param level The Level. 043 * @return The integer value of the priority. 044 */ 045 public static int getPriority(final Facility facility, final Level level) { 046 return (facility.getCode() << 3) + Severity.getSeverity(level).getCode(); 047 } 048 049 /** 050 * Returns the Facility. 051 * @return the Facility. 052 */ 053 public Facility getFacility() { 054 return facility; 055 } 056 057 /** 058 * Returns the Severity. 059 * @return the Severity. 060 */ 061 public Severity getSeverity() { 062 return severity; 063 } 064 065 /** 066 * Returns the value of this Priority. 067 * @return the value of this Priority. 068 */ 069 public int getValue() { 070 return facility.getCode() << 3 + severity.getCode(); 071 } 072 073 @Override 074 public String toString() { 075 return Integer.toString(getValue()); 076 } 077 }