The reason you may not be seeing your log message during shutdown may be due to your logger framework registering its own JVM shutdown hook that will prevent logging from occurring. Since shutdown hooks are all run concurrently, their order is non-deterministic. You can try using System.out.println("...") instead in your shutdown code. Java Util Logging (JUL) registers a shutdown hook for example:
private LogManager(Void checked) {
// Add a shutdown hook to close the global handlers.
try {
Runtime.getRuntime().addShutdownHook(new Cleaner());
} catch (IllegalStateException e) {
// If the VM is already shutting down,
// We do not need to register shutdownHook.
}
}
// This private class is used as a shutdown hook.
// It does a "reset" to close all open handlers.
private class Cleaner extends Thread {
private Cleaner() {
super(null, null, "Logging-Cleaner", 0, false);
/* Set context class loader to null in order to avoid
* keeping a strong reference to an application classloader.
*/
this.setContextClassLoader(null);
}
@Override
public void run() {
// This is to ensure the LogManager.<clinit> is completed
// before synchronized block. Otherwise deadlocks are possible.
LogManager mgr = manager;
// set globalHandlersState to STATE_SHUTDOWN atomically so that
// no attempts are made to (re)initialize the handlers or (re)read
// the configuration again. This is terminal state.
configurationLock.lock();
globalHandlersState = STATE_SHUTDOWN;
configurationLock.unlock();
// Do a reset to close all active handlers.
reset();
}
}