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