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