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 * <p> 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 * 49 * @param listener event listener, may not be null. 50 */ 51 void addLoggerRepositoryEventListener( 52 LoggerRepositoryEventListener listener); 53 54 /** 55 * Remove a {@link LoggerRepositoryEventListener} from the repository. 56 * 57 * @param listener listener. 58 */ 59 void removeLoggerRepositoryEventListener( 60 LoggerRepositoryEventListener listener); 61 62 /** 63 * Add a {@link LoggerEventListener} to the repository. The listener 64 * will be called when repository events occur. 65 * 66 * @param listener listener, may not be null. 67 */ 68 void addLoggerEventListener(LoggerEventListener listener); 69 70 /** 71 * Remove a {@link LoggerEventListener} from the repository. 72 * 73 * @param listener listener, may not be null. 74 */ 75 void removeLoggerEventListener(LoggerEventListener listener); 76 77 /** 78 * Get the name of this logger repository. 79 * 80 * @return name, may not be null. 81 */ 82 String getName(); 83 84 /** 85 * A logger repository is a named entity. 86 * 87 * @param repoName new name, may not be null. 88 */ 89 void setName(String repoName); 90 91 /** 92 * Is the current configuration of the repository in its original (pristine) 93 * state? 94 * 95 * @return true if repository is in original state. 96 */ 97 boolean isPristine(); 98 99 /** 100 * Set the pristine flag. 101 * 102 * @param state state 103 * @see #isPristine 104 */ 105 void setPristine(boolean state); 106 107 /** 108 * Requests that a appender removed event be sent to any registered 109 * {@link LoggerEventListener}. 110 * 111 * @param logger The logger from which the appender was removed. 112 * @param appender The appender removed from the logger. 113 */ 114 void fireRemoveAppenderEvent(Category logger, Appender appender); 115 116 /** 117 * Requests that a level changed event be sent to any registered 118 * {@link LoggerEventListener}. 119 * 120 * @param logger The logger which changed levels. 121 */ 122 void fireLevelChangedEvent(Logger logger); 123 124 /** 125 * Requests that a configuration changed event be sent to any registered 126 * {@link LoggerRepositoryEventListener}. 127 */ 128 void fireConfigurationChangedEvent(); 129 130 /** 131 * Return the PluginRegisty for this LoggerRepository. 132 * 133 * @return plug in registry. 134 */ 135 PluginRegistry getPluginRegistry(); 136 137 /** 138 * Return the {@link Scheduler} for this LoggerRepository. 139 * 140 * @return scheduler. 141 */ 142 Scheduler getScheduler(); 143 144 /** 145 * Get the properties specific for this repository. 146 * 147 * @return property map. 148 */ 149 Map<String, String> getProperties(); 150 151 /** 152 * Get the property of this repository. 153 * 154 * @param key property key. 155 * @return key value or null if not set. 156 */ 157 String getProperty(String key); 158 159 /** 160 * Set a property of this repository. 161 * 162 * @param key key, may not be null. 163 * @param value new value, if null, property will be removed. 164 */ 165 void setProperty(String key, String value); 166 167 /** 168 * Errors which cannot be logged, go to the error list. 169 * 170 * @return List 171 */ 172 List<ErrorItem> getErrorList(); 173 174 /** 175 * Errors which cannot be logged, go to the error list. 176 * 177 * @param errorItem an ErrorItem to add to the error list 178 */ 179 void addErrorItem(ErrorItem errorItem); 180 181 /** 182 * A LoggerRepository can also act as a store for various objects used 183 * by log4j components. 184 * 185 * @param key key, may not be null. 186 * @return The object stored under 'key'. 187 */ 188 Object getObject(String key); 189 190 /** 191 * Store an object under 'key'. If no object can be found, null is returned. 192 * 193 * @param key key, may not be null. 194 * @param value value, may be null. 195 */ 196 void putObject(String key, Object value); 197 198 /** 199 * Sets the logger factory used by LoggerRepository.getLogger(String). 200 * 201 * @param loggerFactory factory to use, may not be null 202 */ 203 void setLoggerFactory(LoggerFactory loggerFactory); 204 205 /** 206 * Returns the logger factory used by 207 * LoggerRepository.getLogger(String). 208 * 209 * @return non-null factory 210 */ 211 LoggerFactory getLoggerFactory(); 212 213 }