View Javadoc
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.core.config;
18  
19  import java.util.List;
20  import java.util.Map;
21  
22  import org.apache.logging.log4j.Level;
23  import org.apache.logging.log4j.core.Appender;
24  import org.apache.logging.log4j.core.Filter;
25  import org.apache.logging.log4j.core.LogEvent;
26  import org.apache.logging.log4j.core.Logger;
27  import org.apache.logging.log4j.core.LoggerContext;
28  import org.apache.logging.log4j.core.async.AsyncLoggerConfigDelegate;
29  import org.apache.logging.log4j.core.filter.Filterable;
30  import org.apache.logging.log4j.core.lookup.StrSubstitutor;
31  import org.apache.logging.log4j.core.net.Advertiser;
32  import org.apache.logging.log4j.core.script.ScriptManager;
33  import org.apache.logging.log4j.core.util.NanoClock;
34  import org.apache.logging.log4j.core.util.WatchManager;
35  
36  /**
37   * Interface that must be implemented to create a configuration.
38   * <p>
39   * Custom implementations are recommended to extend {@link AbstractConfiguration}.
40   * </p>
41   *
42   * @see AbstractConfiguration
43   * @see org.apache.logging.log4j.core.LifeCycle2
44   */
45  public interface Configuration extends Filterable {
46  
47      /** Key for storing the Context properties. */
48      String CONTEXT_PROPERTIES = "ContextProperties";
49  
50      /**
51       * Returns the configuration name.
52       *
53       * @return the name of the configuration.
54       */
55      String getName();
56  
57      /**
58       * Locates the appropriate LoggerConfig for a Logger name. This will remove tokens from the package name as
59       * necessary or return the root LoggerConfig if no other matches were found.
60       *
61       * @param name The Logger name.
62       * @return The located LoggerConfig.
63       */
64      LoggerConfig getLoggerConfig(String name);
65  
66      /**
67       * Returns the Appender with the specified name.
68       *
69       * @param <T>  The expected Appender type.
70       * @param name The name of the Appender.
71       * @return the Appender with the specified name or null if the Appender cannot be located.
72       */
73      <T extends Appender> T getAppender(String name);
74  
75      /**
76       * Returns a Map containing all the Appenders and their name.
77       *
78       * @return A Map containing each Appender's name and the Appender object.
79       */
80      Map<String, Appender> getAppenders();
81  
82      void addAppender(final Appender appender);
83  
84      Map<String, LoggerConfig> getLoggers();
85  
86      void addLoggerAppender(Logger logger, Appender appender);
87  
88      void addLoggerFilter(Logger logger, Filter filter);
89  
90      void setLoggerAdditive(Logger logger, boolean additive);
91  
92      void addLogger(final String name, final LoggerConfig loggerConfig);
93  
94      void removeLogger(final String name);
95  
96      /**
97       * Returns the list of packages to scan for plugins for this Configuration.
98       *
99       * @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, never {@code null}, but may be
139 	 * {@link org.apache.logging.log4j.core.config.ConfigurationSource#NULL_SOURCE}.
140 	 */
141     ConfigurationSource getConfigurationSource();
142 
143     /**
144      * <p>
145      * Returns a list of descriptors of the custom levels defined in the current configuration. The returned list does
146      * <em>not</em> include custom levels that are defined in code with direct calls to {@link Level#forName(String, int)}.
147      * </p>
148      * <p>
149      * Note that the list does not include levels of previous configurations. For example, suppose a configuration
150      * contains custom levels A, B and C. The configuration is then modified to contain custom levels B, C and D. For
151      * the new configuration, this method will return only {B, C, D}, that is, only the custom levels defined in
152      * <em>this</em> configuration. The previously defined level A still exists (and can be obtained with
153      * {@link Level#getLevel(String)}), it is just not in the current configuration. {@link Level#values()} will return
154      * {A, B, C, D and the built-in levels}.
155      * </p>
156      *
157      * @return the custom levels defined in the current configuration
158      */
159     List<CustomLevelConfig> getCustomLevels();
160 
161     ScriptManager getScriptManager();
162 
163     /**
164      * Returns the {@code AsyncLoggerConfigDelegate} shared by all
165      * {@code AsyncLoggerConfig} instances defined in this Configuration.
166      *
167      * @return the {@code AsyncLoggerConfigDelegate}
168      */
169     AsyncLoggerConfigDelegate getAsyncLoggerConfigDelegate();
170 
171     /**
172      * Return the WatchManager.
173      *
174      * @return the WatchManager.
175      */
176     WatchManager getWatchManager();
177 
178     /*
179      * (non-Javadoc)
180      *
181      * @see
182      * org.apache.logging.log4j.core.config.ReliabilityStrategyFactory#getReliabilityStrategy(org.apache.logging.log4j
183      * .core.config.LoggerConfig)
184      */
185 
186     ReliabilityStrategy getReliabilityStrategy(LoggerConfig loggerConfig);
187 
188     /**
189      * Returns the {@link NanoClock} instance for this configuration.
190      *
191      * @return the nano clock
192      */
193     NanoClock getNanoClock();
194 
195     /**
196      * Sets the {@link NanoClock} instance for this configuration.
197      *
198      * @param nanoClock the new nano clock for this configuration. Must be non-null.
199      */
200     void setNanoClock(NanoClock nanoClock);
201 
202     /**
203      * Gets the logger context.
204      *
205      * @return the logger context.
206      */
207     LoggerContext getLoggerContext();
208 }