From d1fe98026e541921bfa4ebf7fc73f9932123807f Mon Sep 17 00:00:00 2001 From: Michael L Heuer Date: Thu, 13 Jun 2024 09:19:10 -0500 Subject: [PATCH] fixup logger initialization --- src/main/java/com/github/heuermh/cooper/Cooper.java | 5 +++++ src/main/java/com/github/heuermh/cooper/Ls.java | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/github/heuermh/cooper/Cooper.java b/src/main/java/com/github/heuermh/cooper/Cooper.java index 20ad8d9..098daba 100644 --- a/src/main/java/com/github/heuermh/cooper/Cooper.java +++ b/src/main/java/com/github/heuermh/cooper/Cooper.java @@ -77,6 +77,11 @@ public final class Cooper { */ public static void main(final String[] args) { + // cheat to set system property before initializing logger + if (Arrays.asList(args).contains("--verbose")) { + System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info"); + } + // install a signal handler to exit on SIGPIPE sun.misc.Signal.handle(new sun.misc.Signal("PIPE"), new sun.misc.SignalHandler() { @Override diff --git a/src/main/java/com/github/heuermh/cooper/Ls.java b/src/main/java/com/github/heuermh/cooper/Ls.java index 993f5f1..7aaa9ed 100644 --- a/src/main/java/com/github/heuermh/cooper/Ls.java +++ b/src/main/java/com/github/heuermh/cooper/Ls.java @@ -76,7 +76,7 @@ public final class Ls implements Callable { private List uris; /** Logger. */ - static Logger logger; + private Logger logger = LoggerFactory.getLogger(Ls.class); /** Human readable formatter. */ static final HumanReadableFormatter FORMATTER = new HumanReadableFormatter(); @@ -151,7 +151,14 @@ public static void main(final String[] args) { if (Arrays.asList(args).contains("--verbose")) { System.setProperty("org.slf4j.simpleLogger.defaultLogLevel", "info"); } - logger = LoggerFactory.getLogger(Cooper.class); + + // install a signal handler to exit on SIGPIPE + sun.misc.Signal.handle(new sun.misc.Signal("PIPE"), new sun.misc.SignalHandler() { + @Override + public void handle(final sun.misc.Signal signal) { + System.exit(0); + } + }); System.exit(new CommandLine(new Ls()).execute(args)); }