Return-Path: Delivered-To: apmail-db-ojb-dev-archive@www.apache.org Received: (qmail 18964 invoked from network); 9 Oct 2005 23:54:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 9 Oct 2005 23:54:27 -0000 Received: (qmail 38963 invoked by uid 500); 9 Oct 2005 23:54:26 -0000 Delivered-To: apmail-db-ojb-dev-archive@db.apache.org Received: (qmail 38932 invoked by uid 500); 9 Oct 2005 23:54:26 -0000 Mailing-List: contact ojb-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "OJB Developers List" Reply-To: "OJB Developers List" Delivered-To: mailing list ojb-dev@db.apache.org Received: (qmail 38921 invoked by uid 500); 9 Oct 2005 23:54:26 -0000 Received: (qmail 38918 invoked by uid 99); 9 Oct 2005 23:54:25 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 09 Oct 2005 16:54:25 -0700 Received: (qmail 18910 invoked by uid 1510); 9 Oct 2005 23:54:05 -0000 Date: 9 Oct 2005 23:54:05 -0000 Message-ID: <20051009235405.18909.qmail@minotaur.apache.org> From: arminw@apache.org To: db-ojb-cvs@apache.org Subject: cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/logging LoggerFactoryImpl.java X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N arminw 2005/10/09 16:54:05 Modified: src/java/org/apache/ojb/broker/util/logging Tag: OJB_1_0_RELEASE LoggerFactoryImpl.java Log: minor improvement Revision Changes Path No revision No revision 1.18.2.2 +38 -40 db-ojb/src/java/org/apache/ojb/broker/util/logging/LoggerFactoryImpl.java Index: LoggerFactoryImpl.java =================================================================== RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/logging/LoggerFactoryImpl.java,v retrieving revision 1.18.2.1 retrieving revision 1.18.2.2 diff -u -r1.18.2.1 -r1.18.2.2 --- LoggerFactoryImpl.java 8 Nov 2004 18:16:37 -0000 1.18.2.1 +++ LoggerFactoryImpl.java 9 Oct 2005 23:54:05 -0000 1.18.2.2 @@ -29,9 +29,7 @@ * * @author Thomas Mahler * @author Leandro Rodrigo Saad Cruz - * * @version $Id$ - * * @see jakarta-log4j */ public class LoggerFactoryImpl @@ -46,13 +44,13 @@ private Map cache = new HashMap(); /** The configuration */ private LoggingConfiguration conf; - + // yes. it's a singleton ! private LoggerFactoryImpl() { } - + public static LoggerFactoryImpl getInstance() { return INSTANCE; @@ -60,7 +58,7 @@ private LoggingConfiguration getConfiguration() { - if (conf == null) + if(conf == null) { // this will load the configuration conf = new LoggingConfiguration(); @@ -72,11 +70,12 @@ * returns a minimal logger that needs no configuration * and can thus be safely used during OJB boot phase * (i.e. when OJB.properties have not been loaded). + * * @return Logger the OJB BootLogger */ public Logger getBootLogger() { - if (bootLogger == null) + if(bootLogger == null) { bootLogger = new PoorMansLoggerImpl("BOOT"); // allow user to set boot log level via system property @@ -91,11 +90,12 @@ * returns the default logger. This Logger can * be used when it is not appropriate to use a * dedicated fresh Logger instance. + * * @return default Logger */ public Logger getDefaultLogger() { - if (defaultLogger == null) + if(defaultLogger == null) { defaultLogger = getLogger("DEFAULT"); } @@ -106,6 +106,7 @@ /** * returns a Logger. The Logger is named * after the full qualified name of input parameter clazz + * * @param clazz the Class which name is to be used as name * @return Logger the returned Logger */ @@ -117,53 +118,50 @@ /** * returns a Logger. + * * @param loggerName the name of the Logger * @return Logger the returned Logger */ public Logger getLogger(String loggerName) { + Logger logger; //lookup in the cache first - if (cache.containsKey(loggerName)) - { - //getBootLogger().debug("Returning cached version of Logger[" + loggerName + "]"); - return (Logger) cache.get(loggerName); - } - //getBootLogger().debug("Logger[" + loggerName + "] not cached"); + logger = (Logger) cache.get(loggerName); - Logger logger = null; - Class loggerClass = null; - - try + if(logger == null) { - // get the configuration (not from the configurator because this is independent) - LoggingConfiguration conf = getConfiguration(); - - loggerClass = conf.getLoggerClass(); - getBootLogger().debug("Using logger class " + loggerClass + " for " + loggerName); - logger = (Logger) ClassHelper.newInstance(loggerClass, String.class, loggerName); - - // configure the logger + Class loggerClass = null; try { - getBootLogger().debug("Initializing logger instance " + loggerName); - logger.configure(conf); + // get the configuration (not from the configurator because this is independent) + LoggingConfiguration conf = getConfiguration(); + + loggerClass = conf.getLoggerClass(); + getBootLogger().debug("Using logger class " + loggerClass + " for " + loggerName); + logger = (Logger) ClassHelper.newInstance(loggerClass, String.class, loggerName); + + // configure the logger + try + { + getBootLogger().debug("Initializing logger instance " + loggerName); + logger.configure(conf); + } + catch(Exception ex) + { + logger = getBootLogger(); + logger.error("[" + this.getClass().getName() + "] Could not initialize logger for class " + loggerClass.getName(), ex); + } + + //cache it so we can get it faster the next time + cache.put(loggerName, logger); } - catch (Exception ex) + catch(Throwable t) { logger = getBootLogger(); - logger.error("[" + this.getClass().getName() + "] Could not initialize logger for class " + loggerClass.getName(), ex); + logger.error("[" + this.getClass().getName() + "] Could not set logger for class '" + + (loggerClass != null ? loggerClass.getName() : "null") + "'", t); } - - //cache it so we can get it faster the next time - cache.put(loggerName, logger); - } - catch (Throwable t) - { - logger = getBootLogger(); - logger.error("[" + this.getClass().getName() + "] Could not set logger for class '" - + (loggerClass != null ? loggerClass.getName() : "null") + "'", t); } return logger; } - } --------------------------------------------------------------------- To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org For additional commands, e-mail: ojb-dev-help@db.apache.org