From 96b653da0adbd449ee2efbeac60766b6d30c987d Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 9 Mar 2016 19:26:00 +0000 Subject: [PATCH] Unify gui/console logging --- source/net/filebot/Main.java | 7 ++++++- source/net/filebot/ui/NotificationHandler.java | 10 +++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/source/net/filebot/Main.java b/source/net/filebot/Main.java index f4fcdf6c..ab66f3b7 100644 --- a/source/net/filebot/Main.java +++ b/source/net/filebot/Main.java @@ -29,6 +29,7 @@ import java.security.Permissions; import java.security.Policy; import java.security.ProtectionDomain; import java.util.Map; +import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; @@ -187,7 +188,11 @@ public class Main { try { // GUI logging settings log.addHandler(new NotificationHandler(getApplicationName())); - log.addHandler(createSimpleFileHandler(new File(getApplicationFolder(), "error.log"), Level.WARNING)); // only log errors to file + + // log errors to file + Handler error = createSimpleFileHandler(new File(getApplicationFolder(), "error.log"), Level.WARNING); + log.addHandler(error); + debug.addHandler(error); // use native LaF an all platforms UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); diff --git a/source/net/filebot/ui/NotificationHandler.java b/source/net/filebot/ui/NotificationHandler.java index fd99c7e2..0af861e1 100644 --- a/source/net/filebot/ui/NotificationHandler.java +++ b/source/net/filebot/ui/NotificationHandler.java @@ -31,7 +31,7 @@ public class NotificationHandler extends Handler { this.timeout = timeout; this.manager = manager; - setFormatter(new NotificationFormatter()); + setFormatter(new SimpleMessageFormatter()); setLevel(Level.INFO); } @@ -69,11 +69,15 @@ public class NotificationHandler extends Handler { } - public static class NotificationFormatter extends Formatter { + public static class SimpleMessageFormatter extends Formatter { @Override public String format(LogRecord record) { - return record.getMessage(); + String message = record.getMessage(); + if (message == null && record.getThrown() != null) { + message = record.getThrown().toString(); + } + return message; } }