File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Logger / ShutdownHook Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Logger / ShutdownHook" Watch "Logger / ShutdownHook" New topic

Logger / ShutdownHook

Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 582

Hi guys. I was having a problem with logging in my shutdown hook and noticed a thread was previously posted in this forum with some advice. The thread is

I am working on the OCMJD and I created a thread about my particular problem here.

The thread that was in this forum had some advice about how to solve the problem. There seem to be two solutions mentioned:

1) Add the handler back to the logger in the thread that you add using the addShutdownHook method.
2) Use an anonymous logger.

I have tried (1) and it works. But it doesn't seem like a good solution to me. There's no guarantee of when the LogManagers shutdown hook will be executed. So you could add the handler back to the logger in your shutdown thread, only for it to be removed by the LogManagers shutdown before your shutdown completes.

I have tried (2) and it doesn't work - some of my log statements do not get output. But I wonder am I understanding it correctly? I simply used java.util.logging.Logger.getAnonymousLogger() to get the anonymous logger. But maybe something else was meant?

Any ideas folks?

SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 582

Any ideas guys?
I agree. Here's the link:
subject: Logger / ShutdownHook
It's not a secret anymore!