The following works fine for me, and has for years:
public class ApplicationLifecycleListener implements ServletContextListener
{
private final static Log logger =
LogFactory.getLog(ApplicationLifecycleListener.class);
public void contextInitialized(ServletContextEvent sce)
{
logger.info("Application context initialized.");
}
public void contextDestroyed(ServletContextEvent sce)
{
logger.info("Application context destroyed.");
LogFactory.release(Thread.currentThread().getContextClassLoader());
}
}
HTH,
Tim
> -----Original Message-----
> From: Peter Pimley [mailto:peter@(protected)]
> Sent: Wednesday, January 03, 2007 3:57 PM
> To: Tomcat Users List
> Subject: Re: Undeploying problem with Tomcat 5.5 and Log4J
>
> Caldarale, Charles R wrote:
> > Please don't use finalize() if you can possibly avoid it - it really
> > bogs down the internal workings of the JVM.
> Hello. I'm new here :)
>
> I don't think you're even guaranteed that finalize will be called at all
> are you?
> http://java.sun.com/javase/6/docs/api/java/lang/Object.html#finalize()
>
>
> It's interesting to note that
java.io.OutputStream objects (and so
> FileOutputStreams and, indirectly, FileWriters) call close within their
> finalize method. This means that nine times out of ten you can happily
> forget about them without bothering to call close, and eventually either
> they get finalized and closed, or your entire application exits anyway.
>
> You can get in trouble when the JVM does not exit when you're
> "finished". Could it be possible that within log4j there's a
> FileOutputStream with your log file open that has not been finalized
> yet? IIRC, Log4j keeps secret handles to Logger instances in order to
> give you the same Logger on duplicate calls to getLogger().
>
> If I were in your position I'd have a good look through the log4j
> documentation and try and find ways of explicitly shutting down the
> entire system.
>
> Maybe this is what you're after:
> http://logging.apache.org/log4j/docs/api/org/apache/log4j/LogManager.html#
> shutdown()
>
> (disclaimer: It's been about a year while since I looked at anything in
> that sort of area!)
>
>
> HTH,
> Peter Pimley
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@(protected)
> To unsubscribe, e-mail: users-unsubscribe@(protected)
> For additional commands, e-mail: users-help@(protected)
---------------------------------------------------------------------
To start a new topic, e-mail: users@(protected)
To unsubscribe, e-mail: users-unsubscribe@(protected)
For additional commands, e-mail: users-help@(protected)