From f45f390d5c3ee16688be036a7095236705627ce3 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 9 Mar 2016 16:18:20 +0000 Subject: [PATCH] only log errors to file --- source/net/filebot/Logging.java | 11 +++++++++++ source/net/filebot/Main.java | 9 +++------ ...ificationLogging.java => NotificationHandler.java} | 6 +++--- 3 files changed, 17 insertions(+), 9 deletions(-) rename source/net/filebot/ui/{NotificationLogging.java => NotificationHandler.java} (92%) diff --git a/source/net/filebot/Logging.java b/source/net/filebot/Logging.java index e1331248..91fcfa58 100644 --- a/source/net/filebot/Logging.java +++ b/source/net/filebot/Logging.java @@ -1,5 +1,8 @@ package net.filebot; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; import java.io.PrintStream; import java.util.function.Supplier; import java.util.logging.Formatter; @@ -7,6 +10,8 @@ import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; +import java.util.logging.SimpleFormatter; +import java.util.logging.StreamHandler; import java.util.regex.Pattern; import net.filebot.util.SystemProperty; @@ -29,6 +34,12 @@ public final class Logging { return log; } + public static StreamHandler createSimpleFileHandler(File file, Level level) throws IOException { + StreamHandler handler = new StreamHandler(new FileOutputStream(file, true), new SimpleFormatter()); + handler.setLevel(level); + return handler; + } + public static Supplier format(String format, Object... args) { return () -> String.format(format, args); } diff --git a/source/net/filebot/Main.java b/source/net/filebot/Main.java index 298030ae..f4fcdf6c 100644 --- a/source/net/filebot/Main.java +++ b/source/net/filebot/Main.java @@ -15,7 +15,6 @@ import java.awt.Dialog.ModalityType; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.net.URI; @@ -32,8 +31,6 @@ import java.security.ProtectionDomain; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.logging.StreamHandler; -import java.util.logging.XMLFormatter; import javax.swing.JDialog; import javax.swing.JFrame; @@ -51,7 +48,7 @@ import net.filebot.mac.MacAppUtilities; import net.filebot.ui.FileBotMenuBar; import net.filebot.ui.GettingStartedStage; import net.filebot.ui.MainFrame; -import net.filebot.ui.NotificationLogging; +import net.filebot.ui.NotificationHandler; import net.filebot.ui.PanelBuilder; import net.filebot.ui.SinglePanelFrame; import net.filebot.ui.transfer.FileTransferable; @@ -189,8 +186,8 @@ public class Main { private static void startUserInterface(ArgumentBean args) { try { // GUI logging settings - log.addHandler(new NotificationLogging(getApplicationName())); - log.addHandler(new StreamHandler(new FileOutputStream(new File(getApplicationFolder(), "error.log.xml"), true), new XMLFormatter())); + log.addHandler(new NotificationHandler(getApplicationName())); + log.addHandler(createSimpleFileHandler(new File(getApplicationFolder(), "error.log"), Level.WARNING)); // only log errors to file // use native LaF an all platforms UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); diff --git a/source/net/filebot/ui/NotificationLogging.java b/source/net/filebot/ui/NotificationHandler.java similarity index 92% rename from source/net/filebot/ui/NotificationLogging.java rename to source/net/filebot/ui/NotificationHandler.java index 32dc5466..fd99c7e2 100644 --- a/source/net/filebot/ui/NotificationLogging.java +++ b/source/net/filebot/ui/NotificationHandler.java @@ -16,17 +16,17 @@ import net.filebot.util.ui.notification.MessageNotification; import net.filebot.util.ui.notification.NotificationManager; import net.filebot.util.ui.notification.QueueNotificationLayout; -public class NotificationLogging extends Handler { +public class NotificationHandler extends Handler { private final String title; private final int timeout; private final NotificationManager manager; - public NotificationLogging(String title) { + public NotificationHandler(String title) { this(title, 2500, new NotificationManager(new QueueNotificationLayout(NORTH, SOUTH))); } - public NotificationLogging(String title, int timeout, NotificationManager manager) { + public NotificationHandler(String title, int timeout, NotificationManager manager) { this.title = title; this.timeout = timeout; this.manager = manager;