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 18 package org.apache.log4j.spi; 19 20 import org.apache.log4j.Appender; 21 import org.apache.log4j.Category; 22 import org.apache.log4j.Logger; 23 import org.apache.log4j.plugins.PluginRegistry; 24 import org.apache.log4j.scheduler.Scheduler; 25 26 import java.util.List; 27 import java.util.Map; 28 29 30 /** 31 A <code>LoggerRepository</code> is used to create and retrieve 32 <code>Loggers</code>. The relation between loggers in a repository 33 depends on the repository but typically loggers are arranged in a 34 named hierarchy. 35 36 <p>In addition to the creational methods, a 37 <code>LoggerRepository</code> can be queried for existing loggers, 38 can act as a point of registry for events related to loggers. 39 40 @author Ceki Gülcü 41 @author Mark Womack 42 @author Curt Arnold 43 */ 44 public interface LoggerRepositoryEx extends LoggerRepository { 45 /** 46 Add a {@link LoggerRepositoryEventListener} to the repository. The 47 listener will be called when repository events occur. 48 @param listener event listener, may not be null. 49 */ 50 void addLoggerRepositoryEventListener( 51 LoggerRepositoryEventListener listener); 52 53 /** 54 Remove a {@link LoggerRepositoryEventListener} from the repository. 55 @param listener listener. 56 */ 57 void removeLoggerRepositoryEventListener( 58 LoggerRepositoryEventListener listener); 59 60 /** 61 Add a {@link LoggerEventListener} to the repository. The listener 62 will be called when repository events occur. 63 @param listener listener, may not be null. 64 */ 65 void addLoggerEventListener(LoggerEventListener listener); 66 67 /** 68 Remove a {@link LoggerEventListener} from the repository. 69 @param listener listener, may not be null. 70 */ 71 void removeLoggerEventListener(LoggerEventListener listener); 72 73 /** 74 * Get the name of this logger repository. 75 * @return name, may not be null. 76 */ 77 String getName(); 78 79 /** 80 * A logger repository is a named entity. 81 * @param repoName new name, may not be null. 82 */ 83 void setName(String repoName); 84 85 /** 86 * Is the current configuration of the repository in its original (pristine) 87 * state? 88 * @return true if repository is in original state. 89 * 90 */ 91 boolean isPristine(); 92 93 /** 94 * Set the pristine flag. 95 * @param state state 96 * @see #isPristine 97 */ 98 void setPristine(boolean state); 99 100 /** 101 Requests that a appender removed event be sent to any registered 102 {@link LoggerEventListener}. 103 @param logger The logger from which the appender was removed. 104 @param appender The appender removed from the logger. 105 */ 106 void fireRemoveAppenderEvent(Category logger, Appender appender); 107 108 /** 109 Requests that a level changed event be sent to any registered 110 {@link LoggerEventListener}. 111 @param logger The logger which changed levels. 112 */ 113 void fireLevelChangedEvent(Logger logger); 114 115 /** 116 Requests that a configuration changed event be sent to any registered 117 {@link LoggerRepositoryEventListener}. 118 */ 119 void fireConfigurationChangedEvent(); 120 121 /** 122 * Return the PluginRegisty for this LoggerRepository. 123 * @return plug in registry. 124 */ 125 PluginRegistry getPluginRegistry(); 126 127 /** 128 * Return the {@link Scheduler} for this LoggerRepository. 129 * @return scheduler. 130 */ 131 Scheduler getScheduler(); 132 133 /** 134 * Get the properties specific for this repository. 135 * @return property map. 136 */ 137 Map getProperties(); 138 139 /** 140 * Get the property of this repository. 141 * @param key property key. 142 * @return key value or null if not set. 143 */ 144 String getProperty(String key); 145 146 /** 147 * Set a property of this repository. 148 * @param key key, may not be null. 149 * @param value new value, if null, property will be removed. 150 */ 151 void setProperty(String key, String value); 152 153 /** 154 * Errors which cannot be logged, go to the error list. 155 * 156 * @return List 157 */ 158 List getErrorList(); 159 160 /** 161 * Errors which cannot be logged, go to the error list. 162 * 163 * @param errorItem an ErrorItem to add to the error list 164 */ 165 void addErrorItem(ErrorItem errorItem); 166 167 /** 168 * A LoggerRepository can also act as a store for various objects used 169 * by log4j components. 170 * 171 * @param key key, may not be null. 172 * @return The object stored under 'key'. 173 */ 174 Object getObject(String key); 175 176 /** 177 * Store an object under 'key'. If no object can be found, null is returned. 178 * 179 * @param key key, may not be null. 180 * @param value value, may be null. 181 */ 182 void putObject(String key, Object value); 183 184 /** 185 * Sets the logger factory used by LoggerRepository.getLogger(String). 186 * @param loggerFactory factory to use, may not be null 187 */ 188 void setLoggerFactory(LoggerFactory loggerFactory); 189 190 /** 191 * Returns the logger factory used by 192 * LoggerRepository.getLogger(String). 193 * 194 * @return non-null factory 195 */ 196 LoggerFactory getLoggerFactory(); 197 198 }