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.async.AsyncLoggerConfigDelegate;
28  import org.apache.logging.log4j.core.filter.Filterable;
29  import org.apache.logging.log4j.core.lookup.StrSubstitutor;
30  import org.apache.logging.log4j.core.net.Advertiser;
31  import org.apache.logging.log4j.core.script.ScriptManager;
32  import org.apache.logging.log4j.core.util.NanoClock;
33  import org.apache.logging.log4j.core.util.WatchManager;
34  
35  /**
36   * Interface that must be implemented to create a configuration.
37   */
38  public interface Configuration extends Filterable {
39  
40      /** Key for storing the Context properties. */
41      String CONTEXT_PROPERTIES = "ContextProperties";
42  
43      /**
44       * Returns the configuration name.
45       *
46       * @return the name of the configuration.
47       */
48      String getName();
49  
50      /**
51       * Locates the appropriate LoggerConfig for a Logger name. This will remove tokens from the package name as
52       * necessary or return the root LoggerConfig if no other matches were found.
53       *
54       * @param name The Logger name.
55       * @return The located LoggerConfig.
56       */
57      LoggerConfig getLoggerConfig(String name);
58  
59      /**
60       * Returns the Appender with the specified name.
61       *
62       * @param <T> The expected Appender type.
63       * @param name The name of the Appender.
64       * @return the Appender with the specified name or null if the Appender cannot be located.
65       */
66      <T extends Appender> T getAppender(String name);
67  
68      /**
69       * Returns a Map containing all the Appenders and their name.
70       *
71       * @return A Map containing each Appender's name and the Appender object.
72       */
73      Map<String, Appender> getAppenders();
74  
75      void addAppender(final Appender appender);
76  
77      Map<String, LoggerConfig> getLoggers();
78  
79      void addLoggerAppender(Logger logger, Appender appender);
80  
81      void addLoggerFilter(Logger logger, Filter filter);
82  
83      void setLoggerAdditive(Logger logger, boolean additive);
84  
85      void addLogger(final String name, final LoggerConfig loggerConfig);
86  
87      void removeLogger(final String name);
88  
89      /**
90       * Returns the list of packages to scan for plugins for this Configuration.
91       *
92       * @return the list of plugin packages.
93       * @since 2.1
94       */
95      List<String> getPluginPackages();
96  
97      Map<String, String> getProperties();
98  
99      /**
100      * Returns the root Logger.
101      * @return the root Logger.
102      */
103     LoggerConfig getRootLogger();
104 
105     void addListener(ConfigurationListener listener);
106 
107     void removeListener(ConfigurationListener listener);
108 
109     StrSubstitutor getStrSubstitutor();
110 
111     void createConfiguration(Node node, LogEvent event);
112 
113     <T> T getComponent(String name);
114 
115     void addComponent(String name, Object object);
116 
117     void setAdvertiser(Advertiser advertiser);
118 
119     Advertiser getAdvertiser();
120 
121     boolean isShutdownHookEnabled();
122 
123     ConfigurationScheduler getScheduler();
124 
125     /**
126      * Returns the source of this configuration.
127      *
128      * @return the source of this configuration
129      */
130     ConfigurationSource getConfigurationSource();
131 
132     /**
133      * <p>
134      * Returns a list of descriptors of the custom levels defined in the current configuration. The returned list does
135      * <em>not</em> include custom levels that are defined in code with direct calls to {@link Level#forName(String, int)}.
136      * </p>
137      * <p>
138      * Note that the list does not include levels of previous configurations. For example, suppose a configuration
139      * contains custom levels A, B and C. The configuration is then modified to contain custom levels B, C and D. For
140      * the new configuration, this method will return only {B, C, D}, that is, only the custom levels defined in
141      * <em>this</em> configuration. The previously defined level A still exists (and can be obtained with
142      * {@link Level#getLevel(String)}), it is just not in the current configuration. {@link Level#values()} will return
143      * {A, B, C, D and the built-in levels}.
144      * </p>
145      *
146      * @return the custom levels defined in the current configuration
147      */
148     List<CustomLevelConfig> getCustomLevels();
149 
150     ScriptManager getScriptManager();
151 
152     /**
153      * Returns the {@code AsyncLoggerConfigDelegate} shared by all
154      * {@code AsyncLoggerConfig} instances defined in this Configuration.
155      *
156      * @return the {@code AsyncLoggerConfigDelegate}
157      */
158 	AsyncLoggerConfigDelegate getAsyncLoggerConfigDelegate();
159 
160     /**
161      * Return the WatchManager.
162      * @return the WatchManager.
163      */
164     WatchManager getWatchManager();
165 
166     /*
167      * (non-Javadoc)
168      *
169      * @see
170      * org.apache.logging.log4j.core.config.ReliabilityStrategyFactory#getReliabilityStrategy(org.apache.logging.log4j
171      * .core.config.LoggerConfig)
172      */
173 
174     ReliabilityStrategy getReliabilityStrategy(LoggerConfig loggerConfig);
175 
176     /**
177      * Returns the {@link NanoClock} instance for this configuration.
178      *
179      * @return the nano clock
180      */
181     NanoClock getNanoClock();
182 
183     /**
184      * Sets the {@link NanoClock} instance for this configuration.
185      *
186      * @param nanoClock the new nano clock for this configuration. Must be non-null.
187      */
188     void setNanoClock(NanoClock nanoClock);
189 }