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 java.util.List;
020import java.util.Map;
021
022import org.apache.logging.log4j.Level;
023import org.apache.logging.log4j.core.Appender;
024import org.apache.logging.log4j.core.Filter;
025import org.apache.logging.log4j.core.LogEvent;
026import org.apache.logging.log4j.core.Logger;
027import org.apache.logging.log4j.core.async.AsyncLoggerConfigDelegate;
028import org.apache.logging.log4j.core.filter.Filterable;
029import org.apache.logging.log4j.core.lookup.StrSubstitutor;
030import org.apache.logging.log4j.core.net.Advertiser;
031import org.apache.logging.log4j.core.script.ScriptManager;
032import org.apache.logging.log4j.core.util.NanoClock;
033import org.apache.logging.log4j.core.util.WatchManager;
034
035/**
036 * Interface that must be implemented to create a configuration.
037 */
038public interface Configuration extends Filterable {
039
040    /** Key for storing the Context properties. */
041    String CONTEXT_PROPERTIES = "ContextProperties";
042
043    /**
044     * Returns the configuration name.
045     *
046     * @return the name of the configuration.
047     */
048    String getName();
049
050    /**
051     * Locates the appropriate LoggerConfig for a Logger name. This will remove tokens from the package name as
052     * necessary or return the root LoggerConfig if no other matches were found.
053     *
054     * @param name The Logger name.
055     * @return The located LoggerConfig.
056     */
057    LoggerConfig getLoggerConfig(String name);
058
059    /**
060     * Returns the Appender with the specified name.
061     *
062     * @param <T>  The expected Appender type.
063     * @param name The name of the Appender.
064     * @return the Appender with the specified name or null if the Appender cannot be located.
065     */
066    <T extends Appender> T getAppender(String name);
067
068    /**
069     * Returns a Map containing all the Appenders and their name.
070     *
071     * @return A Map containing each Appender's name and the Appender object.
072     */
073    Map<String, Appender> getAppenders();
074
075    void addAppender(final Appender appender);
076
077    Map<String, LoggerConfig> getLoggers();
078
079    void addLoggerAppender(Logger logger, Appender appender);
080
081    void addLoggerFilter(Logger logger, Filter filter);
082
083    void setLoggerAdditive(Logger logger, boolean additive);
084
085    void addLogger(final String name, final LoggerConfig loggerConfig);
086
087    void removeLogger(final String name);
088
089    /**
090     * Returns the list of packages to scan for plugins for this Configuration.
091     *
092     * @return the list of plugin packages.
093     * @since 2.1
094     */
095    List<String> getPluginPackages();
096
097    Map<String, String> getProperties();
098
099    /**
100     * Returns the root Logger.
101     *
102     * @return the root Logger.
103     */
104    LoggerConfig getRootLogger();
105
106    void addListener(ConfigurationListener listener);
107
108    void removeListener(ConfigurationListener listener);
109
110    StrSubstitutor getStrSubstitutor();
111
112    void createConfiguration(Node node, LogEvent event);
113
114    <T> T getComponent(String name);
115
116    void addComponent(String name, Object object);
117
118    void setAdvertiser(Advertiser advertiser);
119
120    Advertiser getAdvertiser();
121
122    boolean isShutdownHookEnabled();
123
124    ConfigurationScheduler getScheduler();
125
126    /**
127     * Returns the source of this configuration.
128     *
129     * @return the source of this configuration
130     */
131    ConfigurationSource getConfigurationSource();
132
133    /**
134     * <p>
135     * Returns a list of descriptors of the custom levels defined in the current configuration. The returned list does
136     * <em>not</em> include custom levels that are defined in code with direct calls to {@link Level#forName(String, int)}.
137     * </p>
138     * <p>
139     * Note that the list does not include levels of previous configurations. For example, suppose a configuration
140     * contains custom levels A, B and C. The configuration is then modified to contain custom levels B, C and D. For
141     * the new configuration, this method will return only {B, C, D}, that is, only the custom levels defined in
142     * <em>this</em> configuration. The previously defined level A still exists (and can be obtained with
143     * {@link Level#getLevel(String)}), it is just not in the current configuration. {@link Level#values()} will return
144     * {A, B, C, D and the built-in levels}.
145     * </p>
146     *
147     * @return the custom levels defined in the current configuration
148     */
149    List<CustomLevelConfig> getCustomLevels();
150
151    ScriptManager getScriptManager();
152
153    /**
154     * Returns the {@code AsyncLoggerConfigDelegate} shared by all
155     * {@code AsyncLoggerConfig} instances defined in this Configuration.
156     *
157     * @return the {@code AsyncLoggerConfigDelegate}
158     */
159    AsyncLoggerConfigDelegate getAsyncLoggerConfigDelegate();
160
161    /**
162     * Return the WatchManager.
163     *
164     * @return the WatchManager.
165     */
166    WatchManager getWatchManager();
167
168    /*
169     * (non-Javadoc)
170     *
171     * @see
172     * org.apache.logging.log4j.core.config.ReliabilityStrategyFactory#getReliabilityStrategy(org.apache.logging.log4j
173     * .core.config.LoggerConfig)
174     */
175
176    ReliabilityStrategy getReliabilityStrategy(LoggerConfig loggerConfig);
177
178    /**
179     * Returns the {@link NanoClock} instance for this configuration.
180     *
181     * @return the nano clock
182     */
183    NanoClock getNanoClock();
184
185    /**
186     * Sets the {@link NanoClock} instance for this configuration.
187     *
188     * @param nanoClock the new nano clock for this configuration. Must be non-null.
189     */
190    void setNanoClock(NanoClock nanoClock);
191}