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 org.apache.logging.log4j.Level;
20 import org.apache.logging.log4j.core.Appender;
21 import org.apache.logging.log4j.core.Filter;
22 import org.apache.logging.log4j.core.LogEvent;
23 import org.apache.logging.log4j.core.Logger;
24 import org.apache.logging.log4j.core.filter.Filterable;
25 import org.apache.logging.log4j.core.lookup.StrSubstitutor;
26 import org.apache.logging.log4j.core.net.Advertiser;
27
28 import java.util.List;
29 import java.util.Map;
30
31 /**
32 * Interface that must be implemented to create a configuration.
33 */
34 public interface Configuration extends Filterable {
35
36 /** Key for storing the Context properties. */
37 String CONTEXT_PROPERTIES = "ContextProperties";
38
39 /**
40 * Returns the configuration name.
41 *
42 * @return the name of the configuration.
43 */
44 String getName();
45
46 /**
47 * Locates the appropriate LoggerConfig for a Logger name. This will remove tokens from the package name as
48 * necessary or return the root LoggerConfig if no other matches were found.
49 *
50 * @param name The Logger name.
51 * @return The located LoggerConfig.
52 */
53 LoggerConfig getLoggerConfig(String name);
54
55 /**
56 * Returns the Appender with the specified name.
57 *
58 * @param name The name of the Appender.
59 * @return the Appender with the specified name or null if the Appender cannot be located.
60 */
61 Appender getAppender(String name);
62
63 /**
64 * Returns a Map containing all the Appenders and their name.
65 *
66 * @return A Map containing each Appender's name and the Appender object.
67 */
68 Map<String, Appender> getAppenders();
69
70 void addAppender(final Appender appender);
71
72 Map<String, LoggerConfig> getLoggers();
73
74 void addLoggerAppender(Logger logger, Appender appender);
75
76 void addLoggerFilter(Logger logger, Filter filter);
77
78 void setLoggerAdditive(Logger logger, boolean additive);
79
80 void addLogger(final String name, final LoggerConfig loggerConfig);
81
82 void removeLogger(final String name);
83
84 /**
85 * Returns the list of packages to scan for plugins for this Configuration.
86 *
87 * @return the list of plugin packages.
88 * @since 2.1
89 */
90 List<String> getPluginPackages();
91
92 Map<String, String> getProperties();
93
94 void addListener(ConfigurationListener listener);
95
96 void removeListener(ConfigurationListener listener);
97
98 StrSubstitutor getStrSubstitutor();
99
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 }