1 /* 2 * Copyright the original author or authors. 3 * 4 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.mozilla.org/MPL/MPL-1.1.html 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 import org.as2lib.core.BasicClass; 18 import org.as2lib.env.log.Logger; 19 import org.as2lib.env.log.LoggerRepository; 20 import org.as2lib.env.log.logger.AscbLogger; 21 22 /** 23 * {@code AscbLoggerRepository} returns loggers of type {@link AscbLogger}. 24 * 25 * <p>Configuring your global registry, like {@code LogManager} with this repository, 26 * enables you to work externally with the As2lib Logging API, which allows you to 27 * change between different other Logging APIs, but internally with the ASCB Logging 28 * API. You also configure the ASCB Logging API as if you would use it directly. 29 * 30 * <p>Already received loggers are cached by name. Thus there exists only one logger 31 * instance per logger name. 32 * 33 * @author Simon Wacker 34 * @see org.as2lib.env.log.logger.AscbLogger 35 */ 36 class org.as2lib.env.log.repository.AscbLoggerRepository extends BasicClass implements LoggerRepository { 37 38 /** Already received loggers. */ 39 private var loggers:Object; 40 41 /** 42 * Constructs a new {@code AscbLoggerRepository} instance. 43 */ 44 public function AscbLoggerRepository(Void) { 45 loggers = new Object(); 46 } 47 48 /** 49 * Returns a pre-configured logger for the passed-in {@code name}. 50 * 51 * <p>A new logger is created for names to which no logger has been assigned yet. 52 * The new logger is configured with the {@code name}. The logger is then cached by 53 * name and returned for usage. 54 * 55 * @param name the name of the logger to return 56 * @return the logger corresponding to the passed-in {@code name} 57 */ 58 public function getLogger(name:String):Logger { 59 if (loggers[name]) return loggers[name]; 60 var logger:Logger = new AscbLogger(name); 61 loggers[name] = logger; 62 return logger; 63 } 64 65 }