You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Jeroen Verhagen <je...@gmail.com> on 2005/03/31 09:52:41 UTC

[commons-logging] Problem renaming logfiles

Hi all,

I using commons-logging with log4j in my webapp. I'm using a
DailyRollingFileAppender and every morning when I start developping I
get the following message in my Tomcat console:

log4j:ERROR Failed to rename [logfile.txt] to ...

I did some investigation using the handle utility from
www.sys-internals.com and found that after a redeploy of my webapp,
Tomcat is keeping open multiple handles to the same logfile probably
causing the rename problem. If I restart Tomcat it has only one handle
to logfile as expected until I redeploy again etc.

Can someone please tell me what's causing this?

I'm using Tomcat 5.0.19 with commons-logging 1.0.3 in its common/lib
dir to also use commons-logging for Tomcat. In every class I declare a
Log like this:

private static Log logger = LogFactory.getLog(MyClass.class);

I tried calling LogFactory.releaseAll() from the webapps
ContextListener.contextDestroyed() and giving the webapp its own
commons-logging.jar but that didn't help.

Thanks for any help and regards,

Jeroen

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [commons-logging] Problem renaming logfiles

Posted by Jeroen Verhagen <je...@gmail.com>.
Hi Simon,

On Apr 1, 2005 3:12 PM, Simon Kitching <sk...@apache.org> wrote:
>
> In general, I would recommend
>    LogFactory.release(Thread.currentThread().getContextClassLoader());
> be called on contextDestroyed in order to clean up commons-logging
> resources for a specific webapp. In the case of Tomcat, however, the
> call to release is done for you by the container so this is not
> necessary. Other containers might not be so helpful..

calling LogFactory.release(Thread.currentThread().getContextClassLoader());
did indeed not solve the problem...

> What the correct log4j cleanup method is depends on how you have
> installed/configured log4j. If log4j is in the WEB-INF/lib directory,
> then I think LogManager.shutdown() is the correct thing to call. If
> log4j is in a shared classloader, however, then you will need to consult
> the log4j documentation in order to figure out how to shut down logging
> for just the webapp being undeployed rather than every webapp in the
> container!

however, calling LogManager.shutdown() did! The multiple handles to
the same logfiles are gone.

Many thanks and regards,

Jeroen

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [commons-logging] Problem renaming logfiles

Posted by Simon Kitching <sk...@apache.org>.
Hi Jeroen,

Jeroen Verhagen wrote:
> I using commons-logging with log4j in my webapp. I'm using a
> DailyRollingFileAppender and every morning when I start developping I
> get the following message in my Tomcat console:
> 
> log4j:ERROR Failed to rename [logfile.txt] to ...
> 
> I did some investigation using the handle utility from
> www.sys-internals.com and found that after a redeploy of my webapp,
> Tomcat is keeping open multiple handles to the same logfile probably
> causing the rename problem. If I restart Tomcat it has only one handle
> to logfile as expected until I redeploy again etc.
> 
> Can someone please tell me what's causing this?
> 
> I'm using Tomcat 5.0.19 with commons-logging 1.0.3 in its common/lib
> dir to also use commons-logging for Tomcat. In every class I declare a
> Log like this:
> 
> private static Log logger = LogFactory.getLog(MyClass.class);
> 
> I tried calling LogFactory.releaseAll() from the webapps
> ContextListener.contextDestroyed() and giving the webapp its own
> commons-logging.jar but that didn't help.
> 
> Thanks for any help and regards,

I expect that you need to ensure that the *log4j* cleanup method
is called when the webapp is undeployed. Calling the *commons logging*
cleanup method is a good idea, but this doesn´t cause
log4j to clean up (in this case, close the log file).

In general, I would recommend
   LogFactory.release(Thread.currentThread().getContextClassLoader());
be called on contextDestroyed in order to clean up commons-logging
resources for a specific webapp. In the case of Tomcat, however, the
call to release is done for you by the container so this is not
necessary. Other containers might not be so helpful..

Note that calling releaseAll can release logging resources for *all
webapps in the container* if commons-logging.jar is in a "shared"
classloader (as is the case by default for tomcat).

What the correct log4j cleanup method is depends on how you have 
installed/configured log4j. If log4j is in the WEB-INF/lib directory, 
then I think LogManager.shutdown() is the correct thing to call. If 
log4j is in a shared classloader, however, then you will need to consult 
the log4j documentation in order to figure out how to shut down logging 
for just the webapp being undeployed rather than every webapp in the 
container!

Some more info on commons-logging can be found here:
   http://wiki.apache.org/jakarta-commons/Logging

Regards,

Simon

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


RE: [commons-logging] Problem renaming logfiles

Posted by Alfredo Ledezma Melendez <al...@mail.telcel.com>.
Good morning,

I had the same problem before on a test environment (Tomcat running locally
on a Winbugs XP machine)...every day the same problem. At that moment, being
to damn stressed, I try the same code on a Linux box,  and no problem at all
renaming. To solve the problem in my test environment, I install WinM2K
Professional.

In conclusion, I think the problem is more related with OS, than Tomcat
thought.
____________________________________________
Alfredo Ledezma Meléndez.
Costumer Record Management
Consultor Externo de Sistemas de Atención a Clientes
RadioMovil DIPSA, S. A. de C. V.
Ejército Nacional No. 488, Col. Anahuac, C.P. 11570
México D.F.

 -----Original Message-----
From: 	Jeroen Verhagen [mailto:jeroenverhagen@gmail.com]
Sent:	Thursday, March 31, 2005 1:53 AM
To:	commons-user@jakarta.apache.org
Subject:	[commons-logging] Problem renaming logfiles

Hi all,

I using commons-logging with log4j in my webapp. I'm using a
DailyRollingFileAppender and every morning when I start developping I
get the following message in my Tomcat console:

log4j:ERROR Failed to rename [logfile.txt] to ...

I did some investigation using the handle utility from
www.sys-internals.com and found that after a redeploy of my webapp,
Tomcat is keeping open multiple handles to the same logfile probably
causing the rename problem. If I restart Tomcat it has only one handle
to logfile as expected until I redeploy again etc.

Can someone please tell me what's causing this?

I'm using Tomcat 5.0.19 with commons-logging 1.0.3 in its common/lib
dir to also use commons-logging for Tomcat. In every class I declare a
Log like this:

private static Log logger = LogFactory.getLog(MyClass.class);

I tried calling LogFactory.releaseAll() from the webapps
ContextListener.contextDestroyed() and giving the webapp its own
commons-logging.jar but that didn't help.

Thanks for any help and regards,

Jeroen

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org