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