CLI: Delay shutdown of logging system until the end of the stop() method
This commit is contained in:
parent
728961d19f
commit
db06ab1be9
@ -2,6 +2,7 @@ package fr.pandacube.lib.cli;
|
||||
|
||||
import fr.pandacube.lib.cli.commands.CommandAdmin;
|
||||
import fr.pandacube.lib.cli.commands.CommandStop;
|
||||
import fr.pandacube.lib.cli.log.CLILogger;
|
||||
import fr.pandacube.lib.util.log.Log;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
@ -91,6 +92,8 @@ public abstract class CLIApplication {
|
||||
Log.severe("Error stopping application " + getName() + " version " + getClass().getPackage().getImplementationVersion(), t);
|
||||
} finally {
|
||||
Log.info("Bye bye.");
|
||||
|
||||
CLILogger.ShutdownHookDelayerLogManager.resetFinally();
|
||||
if (!Thread.currentThread().equals(shutdownThread))
|
||||
System.exit(0);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import java.io.PrintStream;
|
||||
import java.util.Scanner;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogManager;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
@ -20,8 +21,22 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
public class CLILogger {
|
||||
|
||||
static {
|
||||
System.setProperty("java.util.logging.manager", ShutdownHookDelayerLogManager.class.getName());
|
||||
}
|
||||
|
||||
private static Logger logger = null;
|
||||
|
||||
|
||||
public static class ShutdownHookDelayerLogManager extends LogManager {
|
||||
static ShutdownHookDelayerLogManager instance;
|
||||
public ShutdownHookDelayerLogManager() { instance = this; }
|
||||
@Override public void reset() { /* don't reset yet. */ }
|
||||
private void reset0() { super.reset(); }
|
||||
public static void resetFinally() { instance.reset0(); }
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialize and return the logger for this application.
|
||||
* @param cli the CLI instance to use
|
||||
|
Loading…
Reference in New Issue
Block a user