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 to...@apache.org on 2004/06/06 22:33:16 UTC

cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/logging LoggerFactoryImpl.java LoggingConfiguration.java

tomdz       2004/06/06 13:33:16

  Modified:    src/java/org/apache/ojb/broker/util/logging
                        LoggerFactoryImpl.java LoggingConfiguration.java
  Log:
  Fixed bug where log4j would always be used even if no log4j.properties file is present
  Fixed bug where the configuration would be read each time a logger was requested from the factory
  
  Revision  Changes    Path
  1.16      +18 -7     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.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- LoggerFactoryImpl.java	1 Jun 2004 21:42:21 -0000	1.15
  +++ LoggerFactoryImpl.java	6 Jun 2004 20:33:16 -0000	1.16
  @@ -38,24 +38,35 @@
   {
       public static final LoggerFactoryImpl INSTANCE = new LoggerFactoryImpl();
   
  -    Logger defaultLogger = null;
  +    private Logger defaultLogger = null;
   
  -    Logger bootLogger = null;
  +    private Logger bootLogger = null;
   
       /** Used for caching logger instances */
  -    Map cache = new HashMap();
  -
  +    private Map cache = new HashMap();
  +    /** The configuration */
  +    private LoggingConfiguration conf;
  +    
       // yes. it's a singleton !
       private LoggerFactoryImpl()
       {
   
       }
  -
  +    
       public static LoggerFactoryImpl getInstance()
       {
           return INSTANCE;
       }
   
  +    private LoggingConfiguration getConfiguration()
  +    {
  +        if (conf == null)
  +        {
  +            // this will load the configuration
  +            conf = new LoggingConfiguration();
  +        }
  +        return conf;
  +    }
   
       /**
        * returns a minimal logger that needs no configuration
  @@ -125,7 +136,7 @@
           try
           {
               // get the configuration (not from the configurator because this is independent)
  -            LoggingConfiguration conf = new LoggingConfiguration();
  +            LoggingConfiguration conf = getConfiguration();
   
               loggerClass = conf.getLoggerClass();
               getBootLogger().debug("Using logger class " + loggerClass + " for " + loggerName);
  
  
  
  1.7       +30 -20    db-ojb/src/java/org/apache/ojb/broker/util/logging/LoggingConfiguration.java
  
  Index: LoggingConfiguration.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/util/logging/LoggingConfiguration.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- LoggingConfiguration.java	6 Jun 2004 19:44:44 -0000	1.6
  +++ LoggingConfiguration.java	6 Jun 2004 20:33:16 -0000	1.7
  @@ -52,7 +52,7 @@
        */
       public LoggingConfiguration()
       {
  -        load();
  +        super();
       }
   
       /* (non-Javadoc)
  @@ -82,10 +82,13 @@
               {
                   InputStream ojbLogPropFile = contextLoader.getResourceAsStream(OJB_LOGGING_PROPERTIES_FILE);
   
  -                bootLogger.debug("Found logging properties file "+OJB_LOGGING_PROPERTIES_FILE);
  -                properties.load(ojbLogPropFile);
  -                loggerClassName   = getLoggerClass(properties);
  -                _loggerConfigFile = getLoggerConfigFile(properties);
  +                if (ojbLogPropFile != null)
  +                {
  +                    bootLogger.debug("Found logging properties file "+OJB_LOGGING_PROPERTIES_FILE);
  +                    properties.load(ojbLogPropFile);
  +                    loggerClassName   = getLoggerClass(properties);
  +                    _loggerConfigFile = getLoggerConfigFile(properties);
  +                }
               }
               catch (Exception ex)
               {}
  @@ -100,13 +103,16 @@
               {
                   InputStream ojbLogPropFile = contextLoader.getResourceAsStream(ojbPropFile);
   
  -                properties.load(ojbLogPropFile);
  -                loggerClassName   = getLoggerClass(properties);
  -                _loggerConfigFile = getLoggerConfigFile(properties);
  -                if (loggerClassName != null)
  +                if (ojbLogPropFile != null)
                   {
  -                    // deprecation warning will be enabled after 1.0
  -                    //bootLogger.warn("Please use a separate "+OJB_LOGGING_PROPERTIES_FILE+" file to specify your logging settings");
  +                    properties.load(ojbLogPropFile);
  +                    loggerClassName   = getLoggerClass(properties);
  +                    _loggerConfigFile = getLoggerConfigFile(properties);
  +                    if (loggerClassName != null)
  +                    {
  +                        // deprecation warning for after 1.0
  +                        //bootLogger.warn("Please use a separate "+OJB_LOGGING_PROPERTIES_FILE+" file to specify your logging settings");
  +                    }
                   }
               }
               catch (Exception ex)
  @@ -138,10 +144,12 @@
                   // but perhaps there is a log4j.properties file ?
                   try
                   {
  -                    contextLoader.getResourceAsStream("log4j.properties");
  -                    // yep, so use log4j
  -                    _loggerClass      = Log4jLoggerImpl.class;
  -                    _loggerConfigFile = "log4j.properties";
  +                    if (contextLoader.getResourceAsStream("log4j.properties") != null)
  +                    {
  +                        // yep, so use log4j
  +                        _loggerClass      = Log4jLoggerImpl.class;
  +                        _loggerConfigFile = "log4j.properties";
  +                    }
                   }
                   catch (Exception ex)
                   {}
  @@ -150,10 +158,12 @@
                       // or a commons-logging.properties file ?
                       try
                       {
  -                        contextLoader.getResourceAsStream("commons-logging.properties");
  -                        // yep, so use commons-logging
  -                        _loggerClass      = CommonsLoggerImpl.class;
  -                        _loggerConfigFile = "commons-logging.properties";
  +                        if (contextLoader.getResourceAsStream("commons-logging.properties") != null)
  +                        {
  +                            // yep, so use commons-logging
  +                            _loggerClass      = CommonsLoggerImpl.class;
  +                            _loggerConfigFile = "commons-logging.properties";
  +                        }
                       }
                       catch (Exception ex)
                       {}
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org