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; 18 19 import java.io.Serializable; 20 21 /** 22 * Markers are objects that are used to add easily filterable information to log messages. 23 * 24 * Markers can be hierarchical - each Marker may have a parent. This allows for broad categories being subdivided into 25 * more specific categories. An example might be a Marker named "Error" with children named "SystemError" and 26 * "ApplicationError". 27 */ 28 public interface Marker extends Serializable { 29 30 /** 31 * Adds a Marker as a parent to this Marker. 32 * 33 * @param markers The parent markers to add. 34 * @return The current Marker object, thus allowing multiple adds to be concatenated. 35 * @throws IllegalArgumentException if the argument is {@code null} 36 */ 37 Marker addParents(Marker... markers); 38 39 /** 40 * Returns true if the given marker has the same name as this marker. 41 * 42 * @param obj the reference object with which to compare. 43 * @return true if the given marker has the same name as this marker. 44 * @since 2.4 45 */ 46 @Override 47 boolean equals(Object obj); 48 49 /** 50 * Returns the name of this Marker. 51 * 52 * @return The name of the Marker. 53 */ 54 String getName(); 55 56 /** 57 * Returns a list of parents of this Marker. 58 * 59 * @return The parent Markers or {@code null} if this Marker has no parents. 60 */ 61 Marker[] getParents(); 62 63 /** 64 * Returns a hash code value based on the name of this marker. Markers are equal if they have the same name. 65 * 66 * @return the computed hash code 67 * @since 2.4 68 */ 69 @Override 70 int hashCode(); 71 72 /** 73 * Indicates whether this Marker has references to any other Markers. 74 * 75 * @return {@code true} if the Marker has parent Markers 76 */ 77 boolean hasParents(); 78 79 /** 80 * Checks whether this Marker is an instance of the specified Marker. 81 * 82 * @param m The Marker to check. 83 * @return {@code true} if this Marker or one of its ancestors is the specified Marker, {@code false} otherwise. 84 * @throws IllegalArgumentException if the argument is {@code null} 85 */ 86 boolean isInstanceOf(Marker m); 87 88 /** 89 * Checks whether this Marker is an instance of the specified Marker. 90 * 91 * @param name The name of the Marker. 92 * @return {@code true} if this Marker or one of its ancestors matches the specified name, {@code false} otherwise. 93 * @throws IllegalArgumentException if the argument is {@code null} 94 */ 95 boolean isInstanceOf(String name); 96 97 /** 98 * Removes the specified Marker as a parent of this Marker. 99 * 100 * @param marker The marker to remove. 101 * @return {@code true} if the marker was removed. 102 * @throws IllegalArgumentException if the argument is {@code null} 103 */ 104 boolean remove(Marker marker); 105 106 /** 107 * Replaces the set of parent Markers with the provided Markers. 108 * 109 * @param markers The new set of parent Markers or {@code null} to clear the parents. 110 * @return The current Marker object. 111 */ 112 Marker setParents(Marker... markers); 113 }