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 */
017package org.apache.logging.log4j;
018
019import java.io.Serializable;
020
021/**
022 *  Markers are objects that are used to add easily filterable information to log messages.
023 *
024 *  Markers can be hierarchical - each Marker may have a parent. This allows for broad categories
025 *  being subdivided into more specific categories. An example might be a Marker named "Error" with
026 *  children named "SystemError" and "ApplicationError".
027 */
028public interface Marker extends Serializable {
029
030    /**
031     * Returns the name of this Marker.
032     * @return The name of the Marker.
033     */
034    String getName();
035
036    /**
037     * Returns a list of parents of this Marker.
038     * @return The parent Markers or {@code null} if this Marker has no parents.
039     */
040    Marker[] getParents();
041
042    /**
043     * Indicates whether this Marker has references to any other Markers.
044     * @return {@code true} if the Marker has parent Markers
045     */
046    boolean hasParents();
047
048    /**
049     * Checks whether this Marker is an instance of the specified Marker.
050     * @param m The Marker to check.
051     * @return {@code true} if this Marker or one of its ancestors is the specified Marker, {@code false} otherwise.
052     * @throws IllegalArgumentException if the argument is {@code null}
053     */
054    boolean isInstanceOf(Marker m);
055
056    /**
057     * Checks whether this Marker is an instance of the specified Marker.
058     * @param name The name of the Marker.
059     * @return {@code true} if this Marker or one of its ancestors matches the specified name, {@code false} otherwise.
060     * @throws IllegalArgumentException if the argument is {@code null}
061     */
062    boolean isInstanceOf(String name);
063
064    /**
065     * Adds a Marker as a parent to this Marker.
066     * @param markers The parent markers to add.
067     * @return The current Marker object, thus allowing multiple adds to be concatenated.
068     * @throws IllegalArgumentException if the argument is {@code null}
069     */
070    Marker addParents(Marker... markers);
071
072    /**
073     * Replaces the set of parent Markers with the provided Markers.
074     * @param markers The new set of parent Markers or {@code null} to clear the parents.
075     * @return The current Marker object.
076     */
077    Marker setParents(Marker... markers);
078
079    /**
080     * Removes the specified Marker as a parent of this Marker.
081     * @param marker The marker to remove.
082     * @return {@code true} if the marker was removed.
083     * @throws IllegalArgumentException if the argument is {@code null}
084     */
085    boolean remove(Marker marker);
086}