diff --git a/source/net/sourceforge/filebot/Main.java b/source/net/sourceforge/filebot/Main.java index 3c426ba6..65621c81 100644 --- a/source/net/sourceforge/filebot/Main.java +++ b/source/net/sourceforge/filebot/Main.java @@ -13,7 +13,6 @@ import java.security.PermissionCollection; import java.security.Permissions; import java.security.Policy; import java.security.ProtectionDomain; -import java.util.logging.ConsoleHandler; import java.util.logging.Level; import java.util.logging.Logger; @@ -26,7 +25,6 @@ import org.kohsuke.args4j.CmdLineParser; import net.sf.ehcache.CacheManager; import net.sourceforge.filebot.format.ExpressionFormat; import net.sourceforge.filebot.ui.MainFrame; -import net.sourceforge.filebot.ui.NotificationLoggingHandler; import net.sourceforge.filebot.ui.SinglePanelFrame; import net.sourceforge.filebot.ui.panel.sfv.SfvPanelBuilder; @@ -38,7 +36,6 @@ public class Main { */ public static void main(String... args) throws Exception { // initialize this stuff before anything else - initializeLogging(); initializeCache(); initializeSecurityManager(); @@ -121,23 +118,6 @@ public class Main { } - private static void initializeLogging() { - Logger uiLogger = Logger.getLogger("ui"); - - // don't use parent handlers - uiLogger.setUseParentHandlers(false); - - // ui handler - uiLogger.addHandler(new NotificationLoggingHandler()); - - // console handler (for warnings and errors only) - ConsoleHandler consoleHandler = new ConsoleHandler(); - consoleHandler.setLevel(Level.WARNING); - - uiLogger.addHandler(consoleHandler); - } - - /** * Shutdown ehcache properly, so that disk-persistent stores can actually be saved to disk */ diff --git a/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java b/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java index 52f05b62..85858da6 100644 --- a/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java +++ b/source/net/sourceforge/filebot/ui/AbstractSearchPanel.java @@ -3,6 +3,7 @@ package net.sourceforge.filebot.ui; import static javax.swing.ScrollPaneConstants.*; +import static net.sourceforge.filebot.ui.NotificationLogging.*; import static net.sourceforge.tuned.ui.TunedUtilities.*; import java.awt.Window; @@ -197,7 +198,7 @@ public abstract class AbstractSearchPanel extends JComponent { switch (results.size()) { case 0: - Logger.getLogger("ui").log(Level.WARNING, String.format("'%s' has not been found.", requestProcessor.request.getSearchText())); + UILogger.log(Level.WARNING, String.format("'%s' has not been found.", requestProcessor.request.getSearchText())); break; case 1: selectedSearchResult = results.iterator().next(); @@ -227,8 +228,7 @@ public abstract class AbstractSearchPanel extends JComponent { new FetchTask(requestProcessor).execute(); } catch (Exception e) { tab.close(); - - Logger.getLogger("ui").log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e); + UILogger.log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e); } } @@ -278,13 +278,12 @@ public abstract class AbstractSearchPanel extends JComponent { // close tab if no elements were fetched if (get().size() <= 0) { - Logger.getLogger("ui").warning(statusMessage); + UILogger.warning(statusMessage); tab.close(); } } catch (Exception e) { tab.close(); - - Logger.getLogger("ui").log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e); + UILogger.log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e); } finally { tab.setLoading(false); } diff --git a/source/net/sourceforge/filebot/ui/NotificationLoggingHandler.java b/source/net/sourceforge/filebot/ui/NotificationLogging.java similarity index 72% rename from source/net/sourceforge/filebot/ui/NotificationLoggingHandler.java rename to source/net/sourceforge/filebot/ui/NotificationLogging.java index fede5bf9..b94c260c 100644 --- a/source/net/sourceforge/filebot/ui/NotificationLoggingHandler.java +++ b/source/net/sourceforge/filebot/ui/NotificationLogging.java @@ -5,9 +5,11 @@ package net.sourceforge.filebot.ui; import static net.sourceforge.filebot.Settings.*; import static net.sourceforge.tuned.ui.notification.Direction.*; +import java.util.logging.ConsoleHandler; import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.LogRecord; +import java.util.logging.Logger; import javax.swing.Icon; import javax.swing.SwingUtilities; @@ -19,18 +21,39 @@ import net.sourceforge.tuned.ui.notification.NotificationManager; import net.sourceforge.tuned.ui.notification.QueueNotificationLayout; -public class NotificationLoggingHandler extends Handler { +public class NotificationLogging extends Handler { + public static final Logger UILogger = createNotificationLogger("net.sourceforge.filebot.ui"); + + + private static Logger createNotificationLogger(String name) { + Logger log = Logger.getLogger(name); + + // don't use parent handlers + log.setUseParentHandlers(false); + + // ui handler + log.addHandler(new NotificationLogging()); + + // console handler (for warnings and errors only) + ConsoleHandler console = new ConsoleHandler(); + console.setLevel(Level.WARNING); + log.addHandler(console); + + return log; + } + + public final NotificationManager notificationManager; public final int timeout = 2500; - - public NotificationLoggingHandler() { + + public NotificationLogging() { this(new NotificationManager(new QueueNotificationLayout(NORTH, SOUTH))); } - public NotificationLoggingHandler(NotificationManager notificationManager) { + public NotificationLogging(NotificationManager notificationManager) { this.notificationManager = notificationManager; } diff --git a/source/net/sourceforge/filebot/ui/panel/analyze/FileTree.java b/source/net/sourceforge/filebot/ui/panel/analyze/FileTree.java index fc2cff9c..29ae4039 100644 --- a/source/net/sourceforge/filebot/ui/panel/analyze/FileTree.java +++ b/source/net/sourceforge/filebot/ui/panel/analyze/FileTree.java @@ -2,6 +2,8 @@ package net.sourceforge.filebot.ui.panel.analyze; +import static net.sourceforge.filebot.ui.NotificationLogging.*; + import java.awt.Desktop; import java.awt.Font; import java.awt.event.ActionEvent; @@ -18,7 +20,6 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.Action; @@ -101,7 +102,7 @@ public class FileTree extends JTree { } } - + private class OpenExpandCollapsePopup extends JPopupMenu { public OpenExpandCollapsePopup() { @@ -138,7 +139,7 @@ public class FileTree extends JTree { add(collapseAction); } - + private class OpenAction extends AbstractAction { public OpenAction(String text, Collection files) { @@ -153,11 +154,12 @@ public class FileTree extends JTree { Desktop.getDesktop().open((File) file); } } catch (Exception e) { - Logger.getLogger("ui").log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e); + UILogger.log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e); } } } + private final Action expandAction = new AbstractAction("Expand all", ResourceManager.getIcon("tree.expand")) { @Override @@ -213,7 +215,7 @@ public class FileTree extends JTree { private TreeNode parent; - + @Override public TreeNode getParent() { return parent; @@ -269,7 +271,7 @@ public class FileTree extends JTree { private final File file; - + public FileNode(File file) { this.file = file; } @@ -293,7 +295,7 @@ public class FileTree extends JTree { private List children; private String title; - + /** * Creates a root node (no parent, no title, empty list of children) */ diff --git a/source/net/sourceforge/filebot/ui/panel/analyze/FileTreeTransferablePolicy.java b/source/net/sourceforge/filebot/ui/panel/analyze/FileTreeTransferablePolicy.java index 43b3d11e..c811d11f 100644 --- a/source/net/sourceforge/filebot/ui/panel/analyze/FileTreeTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/panel/analyze/FileTreeTransferablePolicy.java @@ -2,10 +2,11 @@ package net.sourceforge.filebot.ui.panel.analyze; +import static net.sourceforge.filebot.ui.NotificationLogging.*; + import java.io.File; import java.util.List; import java.util.logging.Level; -import java.util.logging.Logger; import net.sourceforge.filebot.ui.panel.analyze.FileTree.AbstractTreeNode; import net.sourceforge.filebot.ui.panel.analyze.FileTree.FileNode; @@ -20,7 +21,7 @@ class FileTreeTransferablePolicy extends BackgroundFileTransferablePolicy 0) { - Logger.getLogger("ui").info(String.format("%d files renamed.", renameLog.size())); + UILogger.info(String.format("%d files renamed.", renameLog.size())); } } catch (Exception e) { // could not rename one of the files, revert all changes - Logger.getLogger("ui").warning(e.getMessage()); + UILogger.warning(e.getMessage()); // revert rename operations in reverse order for (ListIterator> iterator = renameLog.listIterator(renameLog.size()); iterator.hasPrevious();) { @@ -69,7 +69,7 @@ class RenameAction extends AbstractAction { iterator.remove(); } else { // failed to revert rename operation - Logger.getLogger("ui").severe("Failed to revert file: " + mapping.getValue()); + UILogger.severe("Failed to revert file: " + mapping.getValue()); } } } diff --git a/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java b/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java index 3a124b61..1bc4752d 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/RenamePanel.java @@ -5,6 +5,7 @@ package net.sourceforge.filebot.ui.panel.rename; import static javax.swing.JOptionPane.*; import static javax.swing.SwingUtilities.*; import static net.sourceforge.filebot.Settings.*; +import static net.sourceforge.filebot.ui.NotificationLogging.*; import static net.sourceforge.tuned.ui.LoadingOverlayPane.*; import static net.sourceforge.tuned.ui.TunedUtilities.*; @@ -19,7 +20,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.Action; @@ -368,7 +368,7 @@ public class RenamePanel extends JComponent { // add remaining file entries renameModel.files().addAll(remainingFiles); } catch (Exception e) { - Logger.getLogger("ui").log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e); + UILogger.log(Level.WARNING, ExceptionUtilities.getRootCauseMessage(e), e); } finally { // auto-match finished namesList.firePropertyChange(LOADING_PROPERTY, true, false); diff --git a/source/net/sourceforge/filebot/ui/panel/sfv/ChecksumTableTransferablePolicy.java b/source/net/sourceforge/filebot/ui/panel/sfv/ChecksumTableTransferablePolicy.java index bebc232a..6833bd1c 100644 --- a/source/net/sourceforge/filebot/ui/panel/sfv/ChecksumTableTransferablePolicy.java +++ b/source/net/sourceforge/filebot/ui/panel/sfv/ChecksumTableTransferablePolicy.java @@ -4,6 +4,7 @@ package net.sourceforge.filebot.ui.panel.sfv; import static java.util.Collections.*; import static net.sourceforge.filebot.hash.VerificationUtilities.*; +import static net.sourceforge.filebot.ui.NotificationLogging.*; import java.io.File; import java.io.IOException; @@ -13,7 +14,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ExecutorService; import java.util.logging.Level; -import java.util.logging.Logger; import net.sourceforge.filebot.MediaTypes; import net.sourceforge.filebot.hash.HashType; @@ -65,7 +65,7 @@ class ChecksumTableTransferablePolicy extends BackgroundFileTransferablePolicy