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.core.config;
018
019import org.apache.logging.log4j.Level;
020import org.apache.logging.log4j.core.Appender;
021import org.apache.logging.log4j.core.Filter;
022import org.apache.logging.log4j.core.LogEvent;
023import org.apache.logging.log4j.core.Logger;
024import org.apache.logging.log4j.core.filter.Filterable;
025import org.apache.logging.log4j.core.lookup.StrSubstitutor;
026import org.apache.logging.log4j.core.net.Advertiser;
027
028import java.util.List;
029import java.util.Map;
030
031/**
032 * Interface that must be implemented to create a configuration.
033 */
034public interface Configuration extends Filterable {
035
036    /** Key for storing the Context properties. */
037    String CONTEXT_PROPERTIES = "ContextProperties";
038
039    /**
040     * Returns the configuration name.
041     * 
042     * @return the name of the configuration.
043     */
044    String getName();
045
046    /**
047     * Locates the appropriate LoggerConfig for a Logger name. This will remove tokens from the package name as
048     * necessary or return the root LoggerConfig if no other matches were found.
049     * 
050     * @param name The Logger name.
051     * @return The located LoggerConfig.
052     */
053    LoggerConfig getLoggerConfig(String name);
054
055    /**
056     * Returns the Appender with the specified name.
057     * 
058     * @param name The name of the Appender.
059     * @return the Appender with the specified name or null if the Appender cannot be located.
060     */
061    Appender getAppender(String name);
062
063    /**
064     * Returns a Map containing all the Appenders and their name.
065     * 
066     * @return A Map containing each Appender's name and the Appender object.
067     */
068    Map<String, Appender> getAppenders();
069
070    void addAppender(final Appender appender);
071
072    Map<String, LoggerConfig> getLoggers();
073
074    void addLoggerAppender(Logger logger, Appender appender);
075
076    void addLoggerFilter(Logger logger, Filter filter);
077
078    void setLoggerAdditive(Logger logger, boolean additive);
079
080    void addLogger(final String name, final LoggerConfig loggerConfig);
081
082    void removeLogger(final String name);
083
084    /**
085     * Returns the list of packages to scan for plugins for this Configuration.
086     *
087     * @return the list of plugin packages.
088     * @since 2.1
089     */
090    List<String> getPluginPackages();
091
092    Map<String, String> getProperties();
093
094    void addListener(ConfigurationListener listener);
095
096    void removeListener(ConfigurationListener listener);
097
098    StrSubstitutor getStrSubstitutor();
099
100    void createConfiguration(Node node, LogEvent event);
101
102    <T> T getComponent(String name);
103
104    void addComponent(String name, Object object);
105
106    void setConfigurationMonitor(ConfigurationMonitor monitor);
107
108    ConfigurationMonitor getConfigurationMonitor();
109
110    void setAdvertiser(Advertiser advertiser);
111
112    Advertiser getAdvertiser();
113
114    boolean isShutdownHookEnabled();
115
116    /**
117     * Returns the source of this configuration.
118     * 
119     * @return the source of this configuration
120     */
121    ConfigurationSource getConfigurationSource();
122
123    /**
124     * <p>
125     * Returns a list of descriptors of the custom levels defined in the current configuration. The returned list does
126     * <em>not</em> include custom levels that are defined in code with direct calls to {@link Level#forName(String, int)}.
127     * </p>
128     * <p>
129     * Note that the list does not include levels of previous configurations. For example, suppose a configuration
130     * contains custom levels A, B and C. The configuration is then modified to contain custom levels B, C and D. For
131     * the new configuration, this method will return only {B, C, D}, that is, only the custom levels defined in
132     * <em>this</em> configuration. The previously defined level A still exists (and can be obtained with
133     * {@link Level#getLevel(String)}), it is just not in the current configuration. {@link Level#values()} will return
134     * {A, B, C, D and the built-in levels}.
135     * </p>
136     * 
137     * @return the custom levels defined in the current configuration
138     */
139    List<CustomLevelConfig> getCustomLevels();
140}