Bug 42148 - PropertyConfigurator.configure() does not close properties file
Summary: PropertyConfigurator.configure() does not close properties file
Status: RESOLVED DUPLICATE of bug 40944
Alias: None
Product: Log4j - Now in Jira
Classification: Unclassified
Component: Configurator (show other bugs)
Version: 1.2
Hardware: All Windows XP
: P1 blocker
Target Milestone: ---
Assignee: log4j-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-17 07:52 UTC by Per Lindberg
Modified: 2007-04-19 06:22 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Per Lindberg 2007-04-17 07:52:00 UTC
We have a webapp that must be able to start logging during production.

Our solution is to start a timer thread from its ContextListener that regularly 
re-initializes the configuration from a log4j.properties file:

   LogManager.resetConfiguration();
      ClassLoader cl = this.getClass().getClassLoader();
      URL log4jPropsUrl = cl.getResource("log4j.properties");
      if (log4jPropsUrl != null)
         PropertyConfigurator.configure(log4jPropsUrl);
      else
         log.warn("log4j properties not found");

However, this locks the log4j.properties file, located in the webapp directory, 
so that a hot redeploy fails; Tomcat can't delete log4j.properties since it is 
locked. That is a show-stopper for us.

I have checked the source code of PropertyConfigurator, and think I have found 
the bug. The method doConfigure calls

   props.load(configUrl.openStream());

but it does not call close() on the resulting InputStream. It must be closed, 
or the file will be locked, at least on Windows. A fix may look like:

  InputStream is = configUrl.openStream();
  props.load(is);
  is.close();

We have encountered serveral other problems with files locked by log4j, but 
they are harder to track down. Searching the web also turns up several 
frustrations with files unnecessarily locked by log4j. It would therefore 
probably be a very good idea to search the log4j source code for similar 
constructs elsewhere and add close() wherever necessary.
Comment 1 Curt Arnold 2007-04-17 08:44:19 UTC
This looks exactly like bug 40944 which is fixed in the SVN.  The fix was in the first release candidate for 
log4j 1.2.15 (currently at http://people.apache.org/builds/logging/log4j/1.2.15/) which failed to be 
released due to lack of sufficient votes.  Please check if that takes care of your observed problem.

*** This bug has been marked as a duplicate of 40944 ***
Comment 2 Per Lindberg 2007-04-19 06:22:32 UTC
Yes, I have just verified that the fix in log4j 1.2.15 RC1 solves the problem.
Excellent! Many thanks!