You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2005/10/10 01:54:05 UTC
cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/logging LoggerFactoryImpl.java
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 <a href="leandro@ibnetwork.com.br">Leandro Rodrigo Saad Cruz</a>
- *
* @version $Id$
- *
* @see <a href="http://jakarta.apache.org/log4j/docs/index.html">jakarta-log4j</a>
*/
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