db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/util/logging LoggingConfiguration.java
Date Sun, 19 Dec 2004 02:47:52 GMT
arminw      2004/12/18 18:47:52

  Modified:    src/java/org/apache/ojb/broker/util/logging
                        LoggingConfiguration.java
  Log:
  always close used InputStream instance
  
  Revision  Changes    Path
  1.10      +39 -18    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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- LoggingConfiguration.java	14 Nov 2004 09:36:43 -0000	1.9
  +++ LoggingConfiguration.java	19 Dec 2004 02:47:52 -0000	1.10
  @@ -76,21 +76,27 @@
           loggerClassName   = getLoggerClass(System.getProperties());
           _loggerConfigFile = getLoggerConfigFile(System.getProperties());
   
  +        InputStream ojbLogPropFile = null;
           if (loggerClassName == null)
           {
               // now we're trying to load the OJB-logging.properties file
               String ojbLoggingPropFile = System.getProperty(OJB_LOGGING_PROPERTIES_FILE,
OJB_LOGGING_PROPERTIES_FILE);
  -
               try
               {
  -                InputStream ojbLogPropFile = contextLoader.getResourceAsStream(OJB_LOGGING_PROPERTIES_FILE);
  -
  +                ojbLogPropFile = contextLoader.getResourceAsStream(ojbLoggingPropFile);
                   if (ojbLogPropFile != null)
                   {
  -                    bootLogger.debug("Found logging properties file "+OJB_LOGGING_PROPERTIES_FILE);
  -                    _properties.load(ojbLogPropFile);
  -                    loggerClassName   = getLoggerClass(_properties);
  -                    _loggerConfigFile = getLoggerConfigFile(_properties);
  +                    try
  +                    {
  +                        bootLogger.info("Found logging properties file: "+ojbLoggingPropFile);
  +                        _properties.load(ojbLogPropFile);
  +                        loggerClassName   = getLoggerClass(_properties);
  +                        _loggerConfigFile = getLoggerConfigFile(_properties);
  +                    }
  +                    finally
  +                    {
  +                        ojbLogPropFile.close();
  +                    }
                   }
               }
               catch (Exception ex)
  @@ -104,17 +110,23 @@
   
               try
               {
  -                InputStream ojbLogPropFile = contextLoader.getResourceAsStream(ojbPropFile);
  -
  +                ojbLogPropFile = contextLoader.getResourceAsStream(ojbPropFile);
                   if (ojbLogPropFile != null)
                   {
  -                    _properties.load(ojbLogPropFile);
  -                    loggerClassName   = getLoggerClass(_properties);
  -                    _loggerConfigFile = getLoggerConfigFile(_properties);
  -                    if (loggerClassName != null)
  +                    try
  +                    {
  +                        _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");
  +                        }
  +                    }
  +                    finally
                       {
  -                        // deprecation warning for after 1.0
  -                        //bootLogger.warn("Please use a separate "+OJB_LOGGING_PROPERTIES_FILE+"
file to specify your logging settings");
  +                        ojbLogPropFile.close();
                       }
                   }
               }
  @@ -126,6 +138,7 @@
               try
               {
                   _loggerClass = ClassHelper.getClass(loggerClassName);
  +                bootLogger.info("Logging: Found logger class '" + loggerClassName);
               }
               catch (ClassNotFoundException ex)
               {
  @@ -141,17 +154,21 @@
               {
                   // yep, so use commons-logging
                   _loggerClass = CommonsLoggerImpl.class;
  +                bootLogger.info("Logging: Found commons logging properties, use " + _loggerClass);
               }
               else
               {
                   // but perhaps there is a log4j.properties file ?
                   try
                   {
  -                    if (contextLoader.getResourceAsStream("log4j.properties") != null)
  +                    ojbLogPropFile = contextLoader.getResourceAsStream("log4j.properties");
  +                    if (ojbLogPropFile != null)
                       {
                           // yep, so use log4j
                           _loggerClass      = Log4jLoggerImpl.class;
                           _loggerConfigFile = "log4j.properties";
  +                        bootLogger.info("Logging: Found 'log4j.properties' file, use "
+ _loggerClass);
  +                        ojbLogPropFile.close();
                       }
                   }
                   catch (Exception ex)
  @@ -161,16 +178,20 @@
                       // or a commons-logging.properties file ?
                       try
                       {
  -                        if (contextLoader.getResourceAsStream("commons-logging.properties")
!= null)
  +                        ojbLogPropFile = contextLoader.getResourceAsStream("commons-logging.properties");
  +                        if (ojbLogPropFile != null)
                           {
                               // yep, so use commons-logging
                               _loggerClass      = CommonsLoggerImpl.class;
                               _loggerConfigFile = "commons-logging.properties";
  +                            bootLogger.info("Logging: Found 'commons-logging.properties'
file, use " + _loggerClass);
  +                            ojbLogPropFile.close();
                           }
                       }
                       catch (Exception ex)
                       {}
                       // no, so default to poor man's logging
  +                    bootLogger.info("** Can't find logging configuration file, use default
logger **");
                       _loggerClass = PoorMansLoggerImpl.class;
                   }
               }
  
  
  

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


Mime
View raw message