From 78c3b6917dc2d975803c91a7be1b88326de7494c Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Wed, 9 Mar 2016 20:36:28 +0000 Subject: [PATCH] Unify gui/console logging --- source/net/filebot/Cache.java | 1 + source/net/filebot/History.java | 6 ++-- source/net/filebot/HistorySpooler.java | 6 ++-- source/net/filebot/Main.java | 13 ++++--- source/net/filebot/Settings.java | 4 +-- source/net/filebot/UserFiles.java | 4 +-- source/net/filebot/WebServices.java | 4 +-- .../net/filebot/archive/SevenZipLoader.java | 5 ++- source/net/filebot/cli/ArgumentBean.java | 4 +-- .../net/filebot/cli/FolderWatchService.java | 6 ++-- .../filebot/format/ExpressionFileFilter.java | 5 ++- .../filebot/hash/VerificationFileReader.java | 6 ++-- source/net/filebot/mac/DropToUnlock.java | 6 ++-- source/net/filebot/mac/MacAppUtilities.java | 13 ++++--- source/net/filebot/media/MediaDetection.java | 35 +++++++++---------- source/net/filebot/mediainfo/MediaInfo.java | 6 ++-- .../filebot/similarity/EpisodeMetrics.java | 9 +++-- .../net/filebot/subtitle/SubtitleMetrics.java | 7 ++-- .../net/filebot/subtitle/SubtitleReader.java | 13 ++----- .../filebot/subtitle/SubtitleUtilities.java | 5 ++- .../net/filebot/ui/AbstractSearchPanel.java | 5 ++- source/net/filebot/ui/FileBotMenuBar.java | 4 +-- .../net/filebot/ui/GettingStartedStage.java | 10 +++--- source/net/filebot/ui/MainFrame.java | 3 +- .../net/filebot/ui/analyze/AttributeTool.java | 5 ++- source/net/filebot/ui/analyze/Tool.java | 5 +-- .../rename/FilesListTransferablePolicy.java | 3 +- .../net/filebot/ui/rename/FormatDialog.java | 11 +++--- .../ui/rename/HighlightListCellRenderer.java | 5 +-- .../net/filebot/ui/rename/HistoryDialog.java | 4 +-- source/net/filebot/ui/rename/MatchAction.java | 6 ++-- .../filebot/ui/rename/MovieHashMatcher.java | 4 +-- .../net/filebot/ui/rename/RenameAction.java | 5 ++- source/net/filebot/ui/rename/RenamePanel.java | 17 +++++---- .../net/filebot/ui/rename/ValidateDialog.java | 4 +-- .../ui/subtitle/SubtitleAutoMatchDialog.java | 8 ++--- .../filebot/ui/subtitle/SubtitlePanel.java | 3 +- .../ui/subtitle/upload/MovieEditor.java | 3 +- .../subtitle/upload/SubtitleUploadDialog.java | 10 +++--- .../filebot/ui/transfer/FileTransferable.java | 6 ++-- .../net/filebot/ui/transfer/SaveAction.java | 4 +-- .../ui/transfer/TransferablePolicy.java | 7 ++-- source/net/filebot/util/FileUtilities.java | 4 +-- source/net/filebot/util/PreferencesMap.java | 5 +-- source/net/filebot/util/SystemProperty.java | 5 +-- source/net/filebot/util/Timer.java | 7 ++-- source/net/filebot/util/ui/LinkButton.java | 5 +-- source/net/filebot/web/AcoustIDClient.java | 6 ++-- source/net/filebot/web/AnidbClient.java | 4 +-- source/net/filebot/web/ID3Lookup.java | 4 +-- .../net/filebot/web/OpenSubtitlesClient.java | 3 +- .../net/filebot/web/OpenSubtitlesXmlRpc.java | 8 ++--- source/net/filebot/web/TMDbClient.java | 3 +- source/net/filebot/web/TheTVDBClient.java | 3 +- source/net/filebot/web/WebRequest.java | 4 +-- 55 files changed, 164 insertions(+), 187 deletions(-) diff --git a/source/net/filebot/Cache.java b/source/net/filebot/Cache.java index eb4081a9..835032cc 100644 --- a/source/net/filebot/Cache.java +++ b/source/net/filebot/Cache.java @@ -159,6 +159,7 @@ public class Cache { return (V) super.computeIf(key, condition, compute); } + @Override public V computeIfAbsent(Object key, Compute compute) throws Exception { return (V) super.computeIfAbsent(key, compute); } diff --git a/source/net/filebot/History.java b/source/net/filebot/History.java index 2d2c573d..525d2616 100644 --- a/source/net/filebot/History.java +++ b/source/net/filebot/History.java @@ -1,6 +1,7 @@ package net.filebot; import static java.util.Collections.*; +import static net.filebot.Logging.*; import java.io.File; import java.io.InputStream; @@ -13,7 +14,6 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; -import java.util.logging.Logger; import javax.xml.bind.JAXBContext; import javax.xml.bind.Marshaller; @@ -200,7 +200,7 @@ public class History { marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(history, output); } catch (Exception e) { - Logger.getLogger(History.class.getName()).log(Level.SEVERE, "Failed to write history", e); + debug.log(Level.SEVERE, "Failed to write history", e); } } @@ -209,7 +209,7 @@ public class History { Unmarshaller unmarshaller = JAXBContext.newInstance(History.class).createUnmarshaller(); return ((History) unmarshaller.unmarshal(stream)); } catch (Exception e) { - Logger.getLogger(History.class.getName()).log(Level.SEVERE, "Failed to read history", e); + debug.log(Level.SEVERE, "Failed to read history", e); // fail-safe => default to empty history return new History(); diff --git a/source/net/filebot/HistorySpooler.java b/source/net/filebot/HistorySpooler.java index 142df972..be3ddef0 100644 --- a/source/net/filebot/HistorySpooler.java +++ b/source/net/filebot/HistorySpooler.java @@ -1,5 +1,6 @@ package net.filebot; +import static net.filebot.Logging.*; import static net.filebot.Settings.*; import java.io.File; @@ -13,7 +14,6 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.logging.Level; -import java.util.logging.Logger; import net.filebot.History.Element; @@ -75,7 +75,7 @@ public final class HistorySpooler { channel.position(0); history = History.importHistory(new CloseShieldInputStream(Channels.newInputStream(channel))); // keep JAXB from closing the stream } catch (Exception e) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Failed to load rename history.", e); + debug.log(Level.SEVERE, "Failed to load rename history", e); } } @@ -90,7 +90,7 @@ public final class HistorySpooler { } } } catch (Exception e) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, "Failed to write rename history.", e); + debug.log(Level.SEVERE, "Failed to write rename history", e); } } diff --git a/source/net/filebot/Main.java b/source/net/filebot/Main.java index ab66f3b7..3ae468e4 100644 --- a/source/net/filebot/Main.java +++ b/source/net/filebot/Main.java @@ -31,7 +31,6 @@ import java.security.ProtectionDomain; import java.util.Map; import java.util.logging.Handler; import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.JDialog; import javax.swing.JFrame; @@ -161,7 +160,7 @@ public class Main { try { checkUpdate(); } catch (Exception e) { - Logger.getLogger(Main.class.getName()).log(Level.WARNING, "Failed to check for updates", e); + debug.log(Level.WARNING, "Failed to check for updates", e); } } @@ -170,7 +169,7 @@ public class Main { try { checkGettingStarted(); } catch (Exception e) { - Logger.getLogger(Main.class.getName()).log(Level.WARNING, "Failed to show Getting Started help", e); + debug.log(Level.WARNING, "Failed to show Getting Started help", e); } } } catch (CmdLineException e) { @@ -179,7 +178,7 @@ public class Main { System.exit(-1); } catch (Throwable e) { // unexpected error => dump stack - Logger.getLogger(Main.class.getName()).log(Level.SEVERE, "Unexpected error during startup", e); + debug.log(Level.SEVERE, "Unexpected error during startup", e); System.exit(-1); } } @@ -197,7 +196,7 @@ public class Main { // use native LaF an all platforms UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { - debug.log(Level.WARNING, e.getMessage(), e); + debug.log(Level.SEVERE, e.getMessage(), e); } // default frame @@ -379,7 +378,7 @@ public class Main { try { Desktop.getDesktop().browse(URI.create(uri)); } catch (Exception e) { - Logger.getLogger(Main.class.getName()).log(Level.SEVERE, "Failed to open URI: " + uri, e); + debug.log(Level.SEVERE, "Failed to open URI: " + uri, e); } } @@ -434,7 +433,7 @@ public class Main { System.setSecurityManager(new SecurityManager()); } catch (Exception e) { // security manager was probably set via system property - Logger.getLogger(Main.class.getName()).log(Level.WARNING, e.toString(), e); + debug.log(Level.WARNING, e.getMessage(), e); } } diff --git a/source/net/filebot/Settings.java b/source/net/filebot/Settings.java index f6dc7bdc..b8fcecbc 100644 --- a/source/net/filebot/Settings.java +++ b/source/net/filebot/Settings.java @@ -1,5 +1,6 @@ package net.filebot; +import static net.filebot.Logging.*; import static net.filebot.util.FileUtilities.*; import java.awt.GraphicsEnvironment; @@ -10,7 +11,6 @@ import java.util.Map; import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; @@ -129,7 +129,7 @@ public final class Settings { return Integer.parseInt(threadPool); } } catch (Exception e) { - Logger.getLogger(Settings.class.getName()).log(Level.WARNING, e.toString()); + debug.log(Level.WARNING, e.getMessage(), e); } return Runtime.getRuntime().availableProcessors(); diff --git a/source/net/filebot/UserFiles.java b/source/net/filebot/UserFiles.java index b0c51c0f..9f3decbe 100644 --- a/source/net/filebot/UserFiles.java +++ b/source/net/filebot/UserFiles.java @@ -2,6 +2,7 @@ package net.filebot; import static java.util.Arrays.*; import static java.util.Collections.*; +import static net.filebot.Logging.*; import static net.filebot.Settings.*; import static net.filebot.similarity.Normalization.*; import static net.filebot.util.ui.SwingUI.*; @@ -17,7 +18,6 @@ import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.JFileChooser; @@ -37,7 +37,7 @@ public class UserFiles { try { Desktop.getDesktop().open(it); } catch (Exception e) { - Logger.getLogger(UserFiles.class.getName()).log(Level.WARNING, e.toString()); + debug.log(Level.SEVERE, e.getMessage(), e); } }); } diff --git a/source/net/filebot/WebServices.java b/source/net/filebot/WebServices.java index 897867bf..17157be5 100644 --- a/source/net/filebot/WebServices.java +++ b/source/net/filebot/WebServices.java @@ -3,6 +3,7 @@ package net.filebot; import static java.util.Arrays.*; import static java.util.Collections.*; import static java.util.stream.Collectors.*; +import static net.filebot.Logging.*; import static net.filebot.Settings.*; import static net.filebot.media.MediaDetection.*; import static net.filebot.util.FileUtilities.*; @@ -15,7 +16,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.logging.Level; -import java.util.logging.Logger; import net.filebot.media.XattrMetaInfoProvider; import net.filebot.similarity.MetricAvg; @@ -231,7 +231,7 @@ public final class WebServices { return values; } } catch (Exception e) { - Logger.getLogger(WebServices.class.getName()).log(Level.WARNING, e.getMessage(), e); + debug.log(Level.SEVERE, e.getMessage(), e); } return new String[] { "", "" }; } diff --git a/source/net/filebot/archive/SevenZipLoader.java b/source/net/filebot/archive/SevenZipLoader.java index 6164a6fd..2d65ec5f 100644 --- a/source/net/filebot/archive/SevenZipLoader.java +++ b/source/net/filebot/archive/SevenZipLoader.java @@ -1,7 +1,6 @@ package net.filebot.archive; -import java.util.logging.Logger; - +import static net.filebot.Logging.*; import net.sf.sevenzipjbinding.IArchiveOpenCallback; import net.sf.sevenzipjbinding.IInArchive; import net.sf.sevenzipjbinding.IInStream; @@ -27,7 +26,7 @@ public class SevenZipLoader { System.loadLibrary("libgcc_s_seh-1"); } } catch (Throwable e) { - Logger.getLogger(SevenZipLoader.class.getName()).warning("Failed to preload library: " + e); + debug.warning("Failed to preload library: " + e); } System.loadLibrary("7-Zip-JBinding"); diff --git a/source/net/filebot/cli/ArgumentBean.java b/source/net/filebot/cli/ArgumentBean.java index 6c32f1d5..2820bc6f 100644 --- a/source/net/filebot/cli/ArgumentBean.java +++ b/source/net/filebot/cli/ArgumentBean.java @@ -1,6 +1,7 @@ package net.filebot.cli; import static java.util.Collections.*; +import static net.filebot.Logging.*; import static net.filebot.util.FileUtilities.*; import java.io.File; @@ -11,7 +12,6 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.logging.Level; -import java.util.logging.Logger; import net.filebot.Language; @@ -152,7 +152,7 @@ public class ArgumentBean { try { file = file.getCanonicalFile(); } catch (Exception e) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, String.format("Illegal Argument: %s (%s)", e, argument)); + debug.warning(format("Illegal Argument: %s (%s)", e, argument)); } if (resolveFolders && file.isDirectory()) { diff --git a/source/net/filebot/cli/FolderWatchService.java b/source/net/filebot/cli/FolderWatchService.java index f80040e2..245f7644 100644 --- a/source/net/filebot/cli/FolderWatchService.java +++ b/source/net/filebot/cli/FolderWatchService.java @@ -2,6 +2,7 @@ package net.filebot.cli; import static java.nio.file.StandardWatchEventKinds.*; import static java.util.Collections.*; +import static net.filebot.Logging.*; import static net.filebot.util.FileUtilities.*; import java.io.Closeable; @@ -22,7 +23,6 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.logging.Level; -import java.util.logging.Logger; import net.filebot.util.DefaultThreadFactory; import net.filebot.util.Timer; @@ -148,7 +148,7 @@ public abstract class FolderWatchService implements Closeable { commitSet.addAll(listFiles(file)); watchFolder(file); } catch (IOException e) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.getMessage(), e); + debug.log(Level.SEVERE, e.getMessage(), e); } } } @@ -197,7 +197,7 @@ public abstract class FolderWatchService implements Closeable { } catch (InterruptedException e) { // ignore, part of an orderly shutdown } catch (Exception e) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getMessage(), e); + debug.log(Level.WARNING, e.getMessage(), e); } } diff --git a/source/net/filebot/format/ExpressionFileFilter.java b/source/net/filebot/format/ExpressionFileFilter.java index 4fcfa60f..de490bc3 100644 --- a/source/net/filebot/format/ExpressionFileFilter.java +++ b/source/net/filebot/format/ExpressionFileFilter.java @@ -1,11 +1,10 @@ package net.filebot.format; +import static net.filebot.Logging.*; import static net.filebot.media.MediaDetection.*; import java.io.File; import java.io.FileFilter; -import java.util.logging.Level; -import java.util.logging.Logger; public class ExpressionFileFilter implements FileFilter { @@ -26,7 +25,7 @@ public class ExpressionFileFilter implements FileFilter { try { return filter.matches(new MediaBindingBean(readMetaInfo(f), f, null)); } catch (Exception e) { - Logger.getLogger(ExpressionFileFilter.class.getName()).log(Level.WARNING, e.toString()); + debug.warning(format("Expression failed: %s", e)); return error; } } diff --git a/source/net/filebot/hash/VerificationFileReader.java b/source/net/filebot/hash/VerificationFileReader.java index 614bd60c..7d9b57d4 100644 --- a/source/net/filebot/hash/VerificationFileReader.java +++ b/source/net/filebot/hash/VerificationFileReader.java @@ -2,6 +2,8 @@ package net.filebot.hash; +import static net.filebot.Logging.*; + import java.io.Closeable; import java.io.File; import java.io.IOException; @@ -10,8 +12,6 @@ import java.util.Iterator; import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.Scanner; -import java.util.logging.Level; -import java.util.logging.Logger; public class VerificationFileReader implements Iterator>, Closeable { @@ -71,7 +71,7 @@ public class VerificationFileReader implements Iterator>, Cl entry = format.parseObject(line); } catch (ParseException e) { // log and ignore - Logger.getLogger(getClass().getName()).log(Level.WARNING, String.format("Illegal format on line %d: %s", lineNumber, line)); + debug.warning(format("Illegal format on line %d: %s", lineNumber, line)); } } diff --git a/source/net/filebot/mac/DropToUnlock.java b/source/net/filebot/mac/DropToUnlock.java index 39106136..eec3c962 100644 --- a/source/net/filebot/mac/DropToUnlock.java +++ b/source/net/filebot/mac/DropToUnlock.java @@ -38,8 +38,6 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; import java.util.concurrent.RunnableFuture; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -75,7 +73,7 @@ public class DropToUnlock extends JList { try { NSURL_URLByResolvingBookmarkData_startAccessingSecurityScopedResource(persistentSecurityScopedBookmarks.get(bookmarkForFolder.get().getPath())); } catch (Throwable e) { - Logger.getLogger(DropToUnlock.class.getName()).log(Level.WARNING, "NSURL.URLByResolvingBookmarkData.startAccessingSecurityScopedResource: " + e.toString()); + debug.severe("NSURL.URLByResolvingBookmarkData.startAccessingSecurityScopedResource: " + e); } } } @@ -92,7 +90,7 @@ public class DropToUnlock extends JList { String bookmarkData = NSURL_bookmarkDataWithOptions(folder.getPath()); persistentSecurityScopedBookmarks.put(folder.getPath(), bookmarkData); } catch (Throwable e) { - Logger.getLogger(DropToUnlock.class.getName()).log(Level.WARNING, "NSURL.bookmarkDataWithOptions: " + e.toString()); + debug.severe("NSURL.bookmarkDataWithOptions: " + e); } } } diff --git a/source/net/filebot/mac/MacAppUtilities.java b/source/net/filebot/mac/MacAppUtilities.java index 94d9a38e..d1d33fa6 100644 --- a/source/net/filebot/mac/MacAppUtilities.java +++ b/source/net/filebot/mac/MacAppUtilities.java @@ -1,6 +1,7 @@ package net.filebot.mac; import static ca.weblite.objc.util.CocoaUtils.*; +import static net.filebot.Logging.*; import java.awt.EventQueue; import java.awt.SecondaryLoop; @@ -11,8 +12,6 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.JMenuBar; import javax.swing.UIManager; @@ -98,7 +97,7 @@ public class MacAppUtilities { Method setWindowCanFullScreen = fullScreenUtilities.getMethod("setWindowCanFullScreen", new Class[] { Window.class, boolean.class }); setWindowCanFullScreen.invoke(null, window, true); } catch (Throwable t) { - Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "setWindowCanFullScreen not supported: " + t); + debug.warning("setWindowCanFullScreen not supported: " + t); } } @@ -109,7 +108,7 @@ public class MacAppUtilities { Method requestForeground = application.getMethod("requestForeground", new Class[] { boolean.class }); requestForeground.invoke(instance, true); } catch (Throwable t) { - Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "requestForeground not supported: " + t); + debug.warning("requestForeground not supported: " + t); } } @@ -119,7 +118,7 @@ public class MacAppUtilities { Method revealInFinder = fileManager.getMethod("revealInFinder", new Class[] { File.class }); revealInFinder.invoke(null, file); } catch (Throwable t) { - Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "revealInFinder not supported: " + t); + debug.warning("revealInFinder not supported: " + t); } } @@ -130,7 +129,7 @@ public class MacAppUtilities { Method setDefaultMenuBar = application.getMethod("setDefaultMenuBar", new Class[] { JMenuBar.class }); setDefaultMenuBar.invoke(instance, menu); } catch (Throwable t) { - Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "setDefaultMenuBar not supported: " + t); + debug.warning("setDefaultMenuBar not supported: " + t); } } @@ -143,7 +142,7 @@ public class MacAppUtilities { Object closeAllWindows = quitStrategy.getField(field).get(null); setQuitStrategy.invoke(instance, closeAllWindows); } catch (Throwable t) { - Logger.getLogger(MacAppUtilities.class.getName()).log(Level.WARNING, "setQuitStrategy not supported: " + t); + debug.warning("setQuitStrategy not supported: " + t); } } diff --git a/source/net/filebot/media/MediaDetection.java b/source/net/filebot/media/MediaDetection.java index ee555bdd..2e890423 100644 --- a/source/net/filebot/media/MediaDetection.java +++ b/source/net/filebot/media/MediaDetection.java @@ -39,7 +39,6 @@ import java.util.TreeMap; import java.util.TreeSet; import java.util.function.Function; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -81,7 +80,7 @@ public class MediaDetection { try { return releaseInfo.getClutterFileFilter(); } catch (Exception e) { - Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.SEVERE, "Unable to access clutter file filter: " + e.getMessage(), e); + debug.log(Level.SEVERE, "Unable to access clutter file filter: " + e.getMessage(), e); } return ((File f) -> false); } @@ -319,14 +318,14 @@ public class MediaDetection { unids.add(it.getName()); } } catch (Exception e) { - Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.WARNING, "Failed to lookup info by id: " + e); + debug.warning("Failed to lookup info by id: " + e); } // try to detect series name via known patterns try { - unids.addAll(matchSeriesByDirectMapping(files)); + unids.addAll(matchSeriesByMapping(files)); } catch (Exception e) { - Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.WARNING, "Failed to match direct mappings: " + e); + debug.warning("Failed to match direct mappings: " + e); } // guessed queries @@ -389,7 +388,7 @@ public class MediaDetection { names.addAll(matches); } } catch (Exception e) { - Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.WARNING, "Failed to match folder structure: " + e); + debug.warning("Failed to match folder structure: " + e); } // match common word sequence and clean detected word sequence from unwanted elements @@ -437,7 +436,7 @@ public class MediaDetection { priorityMatchSet.addAll(stripReleaseInfo(matches, false)); matches = stripBlacklistedTerms(priorityMatchSet); } catch (Exception e) { - Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.WARNING, "Failed to clean matches: " + e); + debug.warning("Failed to clean matches: " + e); } names.addAll(matches); @@ -445,7 +444,7 @@ public class MediaDetection { return getUniqueQuerySet(unids, names); } - public static List matchSeriesByDirectMapping(Collection files) throws Exception { + public static List matchSeriesByMapping(Collection files) throws Exception { Map patterns = releaseInfo.getSeriesMappings(); List matches = new ArrayList(); @@ -472,7 +471,7 @@ public class MediaDetection { } } catch (Exception e) { // can't load movie index, just try again next time - Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.SEVERE, "Failed to load series index: " + e); + debug.severe("Failed to load series index: " + e); // rely on online search return emptyList(); @@ -494,7 +493,7 @@ public class MediaDetection { } } catch (Exception e) { // can't load movie index, just try again next time - Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.SEVERE, "Failed to load anime index: " + e); + debug.severe("Failed to load anime index: " + e); // rely on online search return emptyList(); @@ -853,7 +852,7 @@ public class MediaDetection { } } catch (Exception e) { // can't load movie index, just try again next time - Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.SEVERE, "Failed to load movie index: " + e); + debug.severe("Failed to load movie index: " + e); // if we can't use internal index we can only rely on online search return emptyList(); @@ -1188,7 +1187,7 @@ public class MediaDetection { String text = new String(readFile(nfo), "UTF-8"); collection.addAll(grepImdbId(text)); } catch (Exception e) { - Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.WARNING, "Failed to read nfo: " + e.getMessage()); + debug.warning("Failed to read nfo: " + e.getMessage()); } } @@ -1466,7 +1465,7 @@ public class MediaDetection { } } catch (Exception e) { // negative values for invalid files - Logger.getLogger(MediaDetection.class.getClass().getName()).warning(String.format("Unable to read media info: %s [%s]", e.getMessage(), f.getName())); + debug.warning(format("Unable to read media info: %s [%s]", e.getMessage(), f.getName())); Arrays.fill(v, -1); return v; @@ -1500,7 +1499,7 @@ public class MediaDetection { return metaObject; } } catch (Throwable e) { - Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Unable to read xattr: " + e.getMessage()); + debug.warning("Unable to read xattr: " + e.getMessage()); } } return null; @@ -1533,7 +1532,7 @@ public class MediaDetection { if (e instanceof RuntimeException && e.getCause() instanceof IOException) { e = (IOException) e.getCause(); } - Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Failed to set creation date: " + e.getMessage()); + debug.warning("Failed to set creation date: " + e.getMessage()); } } @@ -1550,11 +1549,11 @@ public class MediaDetection { if (e instanceof RuntimeException && e.getCause() instanceof IOException) { e = (IOException) e.getCause(); } - Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Failed to set xattr: " + e.getMessage()); + debug.warning("Failed to set xattr: " + e.getMessage()); } } } catch (Throwable t) { - Logger.getLogger(MediaDetection.class.getClass().getName()).warning("Unable to store xattr: " + t.getMessage()); + debug.warning("Unable to store xattr: " + t.getMessage()); } } } @@ -1563,7 +1562,7 @@ public class MediaDetection { // load filter data MediaDetection.getClutterFileFilter(); MediaDetection.getDiskFolderFilter(); - MediaDetection.matchSeriesByDirectMapping(emptyList()); + MediaDetection.matchSeriesByMapping(emptyList()); // load movie/series index MediaDetection.stripReleaseInfo(singleton(""), true); diff --git a/source/net/filebot/mediainfo/MediaInfo.java b/source/net/filebot/mediainfo/MediaInfo.java index 181e2615..052b251a 100644 --- a/source/net/filebot/mediainfo/MediaInfo.java +++ b/source/net/filebot/mediainfo/MediaInfo.java @@ -1,5 +1,7 @@ package net.filebot.mediainfo; +import static net.filebot.Logging.*; + import java.io.Closeable; import java.io.File; import java.io.IOException; @@ -10,8 +12,6 @@ import java.util.EnumMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; import com.sun.jna.Platform; import com.sun.jna.Pointer; @@ -41,7 +41,7 @@ public class MediaInfo implements Closeable { try (RandomAccessFile raf = new RandomAccessFile(file, "r")) { return openViaBuffer(raf); } catch (IOException e) { - Logger.getLogger(MediaInfo.class.getName()).log(Level.WARNING, e.toString()); + debug.warning("Failed to open random access file: " + e.getMessage()); return false; } } diff --git a/source/net/filebot/similarity/EpisodeMetrics.java b/source/net/filebot/similarity/EpisodeMetrics.java index f9ed13e2..5e2048fe 100644 --- a/source/net/filebot/similarity/EpisodeMetrics.java +++ b/source/net/filebot/similarity/EpisodeMetrics.java @@ -3,6 +3,7 @@ package net.filebot.similarity; import static java.lang.Math.*; import static java.util.Collections.*; import static java.util.regex.Pattern.*; +import static net.filebot.Logging.*; import static net.filebot.media.MediaDetection.*; import static net.filebot.similarity.Normalization.*; import static net.filebot.util.FileUtilities.*; @@ -20,8 +21,6 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -348,12 +347,12 @@ public enum EpisodeMetrics implements SimilarityMetric { // check direct mappings first try { - List directMapping = matchSeriesByDirectMapping(singleton(file)); + List directMapping = matchSeriesByMapping(singleton(file)); if (directMapping.size() > 0) { return directMapping; } } catch (Exception e) { - Logger.getLogger(EpisodeMetrics.class.getName()).log(Level.WARNING, e.getMessage()); + debug.warning("Failed to retrieve series mappings: " + e.getMessage()); } // guess potential series names from path @@ -371,7 +370,7 @@ public enum EpisodeMetrics implements SimilarityMetric { try { return stripReleaseInfo(names, true); } catch (Exception e) { - Logger.getLogger(EpisodeMetrics.class.getName()).log(Level.WARNING, e.getMessage()); + debug.warning("Failed to strip release info: " + e.toString()); } } diff --git a/source/net/filebot/subtitle/SubtitleMetrics.java b/source/net/filebot/subtitle/SubtitleMetrics.java index d37f85b3..edd70c85 100644 --- a/source/net/filebot/subtitle/SubtitleMetrics.java +++ b/source/net/filebot/subtitle/SubtitleMetrics.java @@ -2,6 +2,7 @@ package net.filebot.subtitle; import static java.lang.Math.*; import static java.util.Collections.*; +import static net.filebot.Logging.*; import static net.filebot.media.MediaDetection.*; import static net.filebot.similarity.EpisodeMetrics.*; import static net.filebot.util.FileUtilities.*; @@ -11,8 +12,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.WeakHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -182,7 +181,7 @@ public enum SubtitleMetrics implements SimilarityMetric { } return props; } catch (Exception e) { - Logger.getLogger(SubtitleMetrics.class.getName()).log(Level.WARNING, e.toString()); + debug.warning("Failed to read subtitle properties: " + e); } return emptyMap(); } @@ -207,7 +206,7 @@ public enum SubtitleMetrics implements SimilarityMetric { return props; } } catch (Exception e) { - Logger.getLogger(SubtitleMetrics.class.getName()).log(Level.WARNING, e.toString()); + debug.warning("Failed to read video properties: " + e); } return emptyMap(); }); diff --git a/source/net/filebot/subtitle/SubtitleReader.java b/source/net/filebot/subtitle/SubtitleReader.java index 4e57f30e..746acc0f 100644 --- a/source/net/filebot/subtitle/SubtitleReader.java +++ b/source/net/filebot/subtitle/SubtitleReader.java @@ -1,30 +1,24 @@ - package net.filebot.subtitle; +import static net.filebot.Logging.*; import java.io.Closeable; import java.io.IOException; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Scanner; -import java.util.logging.Level; -import java.util.logging.Logger; - public abstract class SubtitleReader implements Iterator, Closeable { protected final Scanner scanner; protected SubtitleElement current; - public SubtitleReader(Readable source) { this.scanner = new Scanner(source); } - protected abstract SubtitleElement readNext() throws Exception; - @Override public boolean hasNext() { // find next element @@ -33,14 +27,13 @@ public abstract class SubtitleReader implements Iterator, Close current = readNext(); } catch (Exception e) { // log and ignore - Logger.getLogger(getClass().getName()).log(Level.WARNING, "Illegal input: " + e.getMessage()); + debug.warning("Illegal input: " + e.getMessage()); } } return current != null; } - @Override public SubtitleElement next() { if (!hasNext()) { @@ -54,13 +47,11 @@ public abstract class SubtitleReader implements Iterator, Close } } - @Override public void close() throws IOException { scanner.close(); } - @Override public void remove() { throw new UnsupportedOperationException(); diff --git a/source/net/filebot/subtitle/SubtitleUtilities.java b/source/net/filebot/subtitle/SubtitleUtilities.java index 29fe335a..ec9543ab 100644 --- a/source/net/filebot/subtitle/SubtitleUtilities.java +++ b/source/net/filebot/subtitle/SubtitleUtilities.java @@ -3,6 +3,7 @@ package net.filebot.subtitle; import static java.lang.Math.*; import static java.util.Collections.*; import static java.util.stream.Collectors.*; +import static net.filebot.Logging.*; import static net.filebot.MediaTypes.*; import static net.filebot.media.MediaDetection.*; import static net.filebot.similarity.Normalization.*; @@ -29,8 +30,6 @@ import java.util.Map.Entry; import java.util.Set; import java.util.TreeSet; import java.util.function.Predicate; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -154,7 +153,7 @@ public final class SubtitleUtilities { try { selection.addAll(service.guess(getName(f))); } catch (Exception e) { - Logger.getLogger(SubtitleUtilities.class.getName()).log(Level.WARNING, String.format("Failed to identify file [%s]: %s", f.getName(), e.getMessage())); + debug.warning(format("Failed to identify file [%s]: %s", f.getName(), e.getMessage())); } } } diff --git a/source/net/filebot/ui/AbstractSearchPanel.java b/source/net/filebot/ui/AbstractSearchPanel.java index 43e8d68d..e0a21a0f 100644 --- a/source/net/filebot/ui/AbstractSearchPanel.java +++ b/source/net/filebot/ui/AbstractSearchPanel.java @@ -15,7 +15,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.TreeSet; import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.BorderFactory; @@ -96,7 +95,7 @@ public abstract class AbstractSearchPanel extends JComponent { searchHistory.clear(); searchHistory.addAll(get()); } catch (Exception e) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getMessage(), e); + debug.log(Level.WARNING, e.getMessage(), e); } } @@ -110,7 +109,7 @@ public abstract class AbstractSearchPanel extends JComponent { searchTextField.getSelectButton().setSelectedIndex(Integer.parseInt(getSettings().get("engine.selected", "0"))); } catch (Exception e) { // log and ignore - Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getMessage(), e); + debug.log(Level.WARNING, e.getMessage(), e); } // save selected client on change diff --git a/source/net/filebot/ui/FileBotMenuBar.java b/source/net/filebot/ui/FileBotMenuBar.java index 20537b83..018cb8dc 100644 --- a/source/net/filebot/ui/FileBotMenuBar.java +++ b/source/net/filebot/ui/FileBotMenuBar.java @@ -1,11 +1,11 @@ package net.filebot.ui; +import static net.filebot.Logging.*; import static net.filebot.util.ui.SwingUI.*; import java.awt.Desktop; import java.net.URI; import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.Action; import javax.swing.JMenu; @@ -31,7 +31,7 @@ public class FileBotMenuBar { try { Desktop.getDesktop().browse(uri); } catch (Exception e) { - Logger.getLogger(FileBotMenuBar.class.getName()).log(Level.SEVERE, "Failed to open URI: " + uri, e); + debug.log(Level.SEVERE, "Failed to open URI: " + uri, e); } }); } diff --git a/source/net/filebot/ui/GettingStartedStage.java b/source/net/filebot/ui/GettingStartedStage.java index c3e8f50e..d0657afc 100644 --- a/source/net/filebot/ui/GettingStartedStage.java +++ b/source/net/filebot/ui/GettingStartedStage.java @@ -1,5 +1,6 @@ package net.filebot.ui; +import static net.filebot.Logging.*; import static net.filebot.Settings.*; import java.awt.Desktop; @@ -7,7 +8,6 @@ import java.lang.reflect.Field; import java.net.URI; import java.util.Locale; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.stream.Collectors; import javafx.animation.Interpolator; @@ -109,18 +109,18 @@ public class GettingStartedStage { com.sun.webkit.WebPage page = (com.sun.webkit.WebPage) f.get(engine); page.setBackgroundColor(color); } catch (Exception e) { - Logger.getLogger(GettingStartedStage.class.getName()).log(Level.WARNING, "Failed to set background", e); + debug.log(Level.WARNING, "Failed to set background", e); } } protected WebEngine onPopup(WebView webview) { // get currently select image via Galleria API - Object link = webview.getEngine().executeScript("$('.galleria').data('galleria').getData().link"); + Object uri = webview.getEngine().executeScript("$('.galleria').data('galleria').getData().link"); try { - Desktop.getDesktop().browse(new URI(link.toString())); + Desktop.getDesktop().browse(new URI(uri.toString())); } catch (Exception e) { - Logger.getLogger(GettingStartedStage.class.getName()).log(Level.WARNING, "Failed to browse URI", e); + debug.log(Level.SEVERE, "Failed to open URI: " + uri, e); } // prevent current web view from opening the link diff --git a/source/net/filebot/ui/MainFrame.java b/source/net/filebot/ui/MainFrame.java index cbe42e4d..56cea1f2 100644 --- a/source/net/filebot/ui/MainFrame.java +++ b/source/net/filebot/ui/MainFrame.java @@ -21,7 +21,6 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.IOException; import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.JComponent; @@ -143,7 +142,7 @@ public class MainFrame extends JFrame { pad.setLocationByPlatform(true); pad.setVisible(true); } catch (IOException e) { - Logger.getLogger(GroovyPad.class.getName()).log(Level.WARNING, e.getMessage(), e); + debug.log(Level.WARNING, e.getMessage(), e); } finally { setCursor(Cursor.getDefaultCursor()); } diff --git a/source/net/filebot/ui/analyze/AttributeTool.java b/source/net/filebot/ui/analyze/AttributeTool.java index bb8545a4..29fded54 100644 --- a/source/net/filebot/ui/analyze/AttributeTool.java +++ b/source/net/filebot/ui/analyze/AttributeTool.java @@ -1,13 +1,12 @@ package net.filebot.ui.analyze; +import static net.filebot.Logging.*; import static net.filebot.MediaTypes.*; import java.awt.Color; import java.io.File; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.BorderFactory; import javax.swing.JScrollPane; @@ -78,7 +77,7 @@ class AttributeTool extends Tool { model.addRow(metaId, metaObject, originalName, file); } catch (Exception e) { - Logger.getLogger(AttributeTool.class.getName()).log(Level.WARNING, e.getMessage()); + debug.warning("Failed to read xattr: " + e); } } } diff --git a/source/net/filebot/ui/analyze/Tool.java b/source/net/filebot/ui/analyze/Tool.java index d554069b..4a6a4b6b 100644 --- a/source/net/filebot/ui/analyze/Tool.java +++ b/source/net/filebot/ui/analyze/Tool.java @@ -1,12 +1,13 @@ package net.filebot.ui.analyze; +import static net.filebot.Logging.*; + import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.ConcurrentModificationException; import java.util.List; import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.JComponent; import javax.swing.SwingWorker; @@ -79,7 +80,7 @@ abstract class Tool extends JComponent { // if it happens, it is supposed to } else { // should not happen - Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getMessage(), e); + debug.log(Level.WARNING, e.getMessage(), e); } } } diff --git a/source/net/filebot/ui/rename/FilesListTransferablePolicy.java b/source/net/filebot/ui/rename/FilesListTransferablePolicy.java index 3200b7cc..40b48aa3 100644 --- a/source/net/filebot/ui/rename/FilesListTransferablePolicy.java +++ b/source/net/filebot/ui/rename/FilesListTransferablePolicy.java @@ -13,7 +13,6 @@ import java.util.List; import java.util.Scanner; import java.util.Set; import java.util.logging.Level; -import java.util.logging.Logger; import net.filebot.media.MediaDetection; import net.filebot.ui.transfer.BackgroundFileTransferablePolicy; @@ -83,7 +82,7 @@ class FilesListTransferablePolicy extends BackgroundFileTransferablePolicy queue.addAll(0, paths); // add paths from text file } } catch (Exception e) { - Logger.getLogger(FilesListTransferablePolicy.class.getName()).log(Level.WARNING, e.getMessage()); + debug.log(Level.WARNING, e.getMessage(), e); } } else if (!recursive || f.isFile() || MediaDetection.isDiskFolder(f)) { entries.add(f); diff --git a/source/net/filebot/ui/rename/FormatDialog.java b/source/net/filebot/ui/rename/FormatDialog.java index fafb178a..e26487c8 100644 --- a/source/net/filebot/ui/rename/FormatDialog.java +++ b/source/net/filebot/ui/rename/FormatDialog.java @@ -39,7 +39,6 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor.DiscardOldestPolicy; import java.util.concurrent.TimeUnit; import java.util.logging.Level; -import java.util.logging.Logger; import javax.script.ScriptException; import javax.swing.AbstractAction; @@ -418,7 +417,7 @@ public class FormatDialog extends JDialog { try { formatExample.setText(get()); } catch (Exception e) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.getMessage(), e); + debug.log(Level.SEVERE, e.getMessage(), e); } } }.execute(); @@ -451,7 +450,7 @@ public class FormatDialog extends JDialog { String sample = bundle.getString(mode.key() + ".sample"); info = JsonReader.jsonToJava(sample); } catch (Exception illegalSample) { - Logger.getLogger(RenamePanel.class.getName()).log(Level.SEVERE, "Illegal Sample", e); + debug.log(Level.SEVERE, "Illegal Sample", e); } } @@ -482,10 +481,10 @@ public class FormatDialog extends JDialog { threadGroup.stop(); // log access of potentially unsafe method - Logger.getLogger(getClass().getName()).warning("Thread was forcibly terminated"); + debug.warning("Thread was forcibly terminated"); } } catch (Exception e) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, "Thread was not terminated", e); + debug.log(Level.WARNING, "Thread was not terminated", e); } return remaining; @@ -680,7 +679,7 @@ public class FormatDialog extends JDialog { mode.persistentSample().setValue(info == null ? "" : JsonWriter.objectToJson(info)); persistentSampleFile.setValue(file == null ? "" : sample.getFileObject().getAbsolutePath()); } catch (Exception e) { - Logger.getLogger(FormatDialog.class.getName()).log(Level.WARNING, e.getMessage(), e); + debug.log(Level.WARNING, e.getMessage(), e); } // reevaluate everything diff --git a/source/net/filebot/ui/rename/HighlightListCellRenderer.java b/source/net/filebot/ui/rename/HighlightListCellRenderer.java index d699c1ca..3d6fc905 100644 --- a/source/net/filebot/ui/rename/HighlightListCellRenderer.java +++ b/source/net/filebot/ui/rename/HighlightListCellRenderer.java @@ -2,11 +2,12 @@ package net.filebot.ui.rename; +import static net.filebot.Logging.*; + import java.awt.BorderLayout; import java.awt.Color; import java.awt.Insets; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -68,7 +69,7 @@ class HighlightListCellRenderer extends AbstractFancyListCellRenderer { textComponent.getHighlighter().addHighlight(matcher.start(0), matcher.end(0), highlightPainter); } catch (BadLocationException e) { //should not happen - Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e); + debug.log(Level.SEVERE, e.toString(), e); } } } diff --git a/source/net/filebot/ui/rename/HistoryDialog.java b/source/net/filebot/ui/rename/HistoryDialog.java index 47870060..d10ce2b3 100644 --- a/source/net/filebot/ui/rename/HistoryDialog.java +++ b/source/net/filebot/ui/rename/HistoryDialog.java @@ -5,6 +5,7 @@ import static java.util.Arrays.*; import static java.util.Collections.*; import static java.util.regex.Pattern.*; import static javax.swing.JOptionPane.*; +import static net.filebot.Logging.*; import static net.filebot.Settings.*; import static net.filebot.UserFiles.*; import static net.filebot.util.FileUtilities.*; @@ -34,7 +35,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -554,7 +554,7 @@ class HistoryDialog extends JDialog { new MetaAttributes(destination).clear(); } } catch (Exception e) { - Logger.getLogger(HistoryDialog.class.getName()).log(Level.SEVERE, e.getMessage(), e); + debug.log(Level.SEVERE, e.getMessage(), e); } } diff --git a/source/net/filebot/ui/rename/MatchAction.java b/source/net/filebot/ui/rename/MatchAction.java index d552c7cc..dbe11cb0 100644 --- a/source/net/filebot/ui/rename/MatchAction.java +++ b/source/net/filebot/ui/rename/MatchAction.java @@ -1,5 +1,6 @@ package net.filebot.ui.rename; +import static net.filebot.Logging.*; import static net.filebot.util.ui.SwingUI.*; import java.awt.Cursor; @@ -11,7 +12,6 @@ import java.util.List; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.Icon; @@ -65,7 +65,7 @@ class MatchAction extends AbstractAction { // display progress dialog and stop blocking EDT dialog.setVisible(true); } catch (Exception e) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e); + debug.log(Level.SEVERE, e.toString(), e); } finally { window.setCursor(Cursor.getDefaultCursor()); } @@ -121,7 +121,7 @@ class MatchAction extends AbstractAction { // insert objects that could not be matched at the end of the model model.addAll(matcher.remainingValues(), matcher.remainingCandidates()); } catch (Exception e) { - Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e); + debug.log(Level.SEVERE, e.toString(), e); } } diff --git a/source/net/filebot/ui/rename/MovieHashMatcher.java b/source/net/filebot/ui/rename/MovieHashMatcher.java index de731597..e0eac123 100644 --- a/source/net/filebot/ui/rename/MovieHashMatcher.java +++ b/source/net/filebot/ui/rename/MovieHashMatcher.java @@ -1,6 +1,7 @@ package net.filebot.ui.rename; import static java.util.Collections.*; +import static net.filebot.Logging.*; import static net.filebot.MediaTypes.*; import static net.filebot.Settings.*; import static net.filebot.media.MediaDetection.*; @@ -35,7 +36,6 @@ import java.util.concurrent.Future; import java.util.concurrent.FutureTask; import java.util.concurrent.RunnableFuture; import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.Action; import javax.swing.SwingUtilities; @@ -145,7 +145,7 @@ class MovieHashMatcher implements AutoCompleteMatcher { } } } catch (NoSuchElementException e) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, "Failed to grep IMDbID: " + nfo.getName()); + debug.log(Level.WARNING, "Failed to grep IMDbID: " + nfo.getName()); } } diff --git a/source/net/filebot/ui/rename/RenameAction.java b/source/net/filebot/ui/rename/RenameAction.java index 2d1ad8b3..3a93495b 100644 --- a/source/net/filebot/ui/rename/RenameAction.java +++ b/source/net/filebot/ui/rename/RenameAction.java @@ -31,7 +31,6 @@ import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -131,7 +130,7 @@ class RenameAction extends AbstractAction { } } } catch (Throwable e) { - Logger.getLogger(RenameAction.class.getName()).warning("Failed to write xattr: " + e.getMessage()); + debug.warning("Failed to write xattr: " + e.getMessage()); } } } catch (ExecutionException e) { @@ -343,7 +342,7 @@ class RenameAction extends AbstractAction { if (!isCancelled()) { log.log(Level.SEVERE, String.format("%s: %s", getRootCause(e).getClass().getSimpleName(), getRootCauseMessage(e)), e); } else { - Logger.getLogger(RenameAction.class.getName()).log(Level.SEVERE, e.getMessage(), e); + debug.log(Level.SEVERE, e.getMessage(), e); } } diff --git a/source/net/filebot/ui/rename/RenamePanel.java b/source/net/filebot/ui/rename/RenamePanel.java index 63e08e4a..db77cb92 100644 --- a/source/net/filebot/ui/rename/RenamePanel.java +++ b/source/net/filebot/ui/rename/RenamePanel.java @@ -29,7 +29,6 @@ import java.util.Locale; import java.util.Map; import java.util.concurrent.CancellationException; import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.Action; @@ -273,7 +272,7 @@ public class RenamePanel extends JComponent { UserFiles.revealFiles(list.getSelectedValuesList()); } } catch (Exception e) { - Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.getMessage()); + debug.log(Level.WARNING, e.getMessage()); } finally { getWindow(evt.getSource()).setCursor(Cursor.getDefaultCursor()); } @@ -298,7 +297,7 @@ public class RenamePanel extends JComponent { showFormatEditor(sample); } } catch (Exception e) { - Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.getMessage(), e); + debug.log(Level.WARNING, e.getMessage(), e); } finally { getWindow(evt.getSource()).setCursor(Cursor.getDefaultCursor()); } @@ -369,7 +368,7 @@ public class RenamePanel extends JComponent { } } } catch (Exception e) { - Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.getMessage()); + debug.log(Level.WARNING, e.getMessage()); } } }); @@ -389,7 +388,7 @@ public class RenamePanel extends JComponent { Preset p = (Preset) JsonReader.jsonToJava(it); actionPopup.add(new ApplyPresetAction(p)); } catch (Exception e) { - Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.toString()); + debug.log(Level.WARNING, e.toString()); } } actionPopup.addSeparator(); @@ -436,7 +435,7 @@ public class RenamePanel extends JComponent { break; } } catch (Exception e) { - Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.toString()); + debug.log(Level.WARNING, e.toString()); } } }); @@ -516,7 +515,7 @@ public class RenamePanel extends JComponent { } orderCombo.setSelectedItem(SortOrder.forName(persistentPreferredEpisodeOrder.getValue())); } catch (Exception e) { - Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.getMessage(), e); + debug.log(Level.WARNING, e.getMessage(), e); } JScrollPane spModeCombo = new JScrollPane(modeCombo, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); @@ -591,7 +590,7 @@ public class RenamePanel extends JComponent { try { initMode = Mode.valueOf(persistentLastFormatState.getValue()); } catch (Exception e) { - Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, e.getMessage()); + debug.log(Level.WARNING, e.getMessage()); } } @@ -890,7 +889,7 @@ public class RenamePanel extends JComponent { renameModel.files().addAll(remainingFiles); } catch (Exception e) { if (findCause(e, CancellationException.class) != null) { - Logger.getLogger(RenamePanel.class.getName()).log(Level.WARNING, getRootCause(e).toString()); + debug.log(Level.WARNING, getRootCause(e).toString()); } else { log.log(Level.WARNING, String.format("%s: %s", getRootCause(e).getClass().getSimpleName(), getRootCauseMessage(e)), e); } diff --git a/source/net/filebot/ui/rename/ValidateDialog.java b/source/net/filebot/ui/rename/ValidateDialog.java index 4bff5e86..6eca8be8 100644 --- a/source/net/filebot/ui/rename/ValidateDialog.java +++ b/source/net/filebot/ui/rename/ValidateDialog.java @@ -3,6 +3,7 @@ package net.filebot.ui.rename; import static java.util.Collections.*; +import static net.filebot.Logging.*; import static net.filebot.Settings.*; import static net.filebot.util.FileUtilities.*; import static net.filebot.util.ui.SwingUI.*; @@ -20,7 +21,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import javax.swing.AbstractAction; @@ -74,7 +74,7 @@ class ValidateDialog extends JDialog { textComponent.getHighlighter().addHighlight(matcher.start(0), matcher.end(0), highlightPainter); } catch (BadLocationException e) { //should not happen - Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e); + debug.log(Level.SEVERE, e.toString(), e); } } } diff --git a/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java b/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java index f6483124..ad882fe1 100644 --- a/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java +++ b/source/net/filebot/ui/subtitle/SubtitleAutoMatchDialog.java @@ -2,6 +2,7 @@ package net.filebot.ui.subtitle; import static javax.swing.BorderFactory.*; import static javax.swing.JOptionPane.*; +import static net.filebot.Logging.*; import static net.filebot.Settings.*; import static net.filebot.subtitle.SubtitleUtilities.*; import static net.filebot.util.FileUtilities.*; @@ -32,7 +33,6 @@ import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.Action; @@ -291,7 +291,7 @@ class SubtitleAutoMatchDialog extends JDialog { try { mapping.setSubtitleFile(get()); } catch (Exception e) { - Logger.getLogger(SubtitleAutoMatchDialog.class.getName()).log(Level.WARNING, e.getMessage(), e); + debug.log(Level.WARNING, e.getMessage(), e); } } }); @@ -785,7 +785,7 @@ class SubtitleAutoMatchDialog extends JDialog { throw e; } catch (Exception e) { // log and ignore - Logger.getLogger(SubtitleAutoMatchDialog.class.getName()).log(Level.WARNING, e.getMessage()); + debug.log(Level.WARNING, e.getMessage()); } } @@ -833,7 +833,7 @@ class SubtitleAutoMatchDialog extends JDialog { return destination; } catch (Exception e) { - Logger.getLogger(SubtitleAutoMatchDialog.class.getName()).log(Level.WARNING, e.getMessage(), e); + debug.log(Level.WARNING, e.getMessage(), e); } return null; diff --git a/source/net/filebot/ui/subtitle/SubtitlePanel.java b/source/net/filebot/ui/subtitle/SubtitlePanel.java index 8c272eaa..63e6a576 100644 --- a/source/net/filebot/ui/subtitle/SubtitlePanel.java +++ b/source/net/filebot/ui/subtitle/SubtitlePanel.java @@ -22,7 +22,6 @@ import java.util.Locale; import java.util.Map; import java.util.function.Function; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -377,7 +376,7 @@ public class SubtitlePanel extends AbstractSearchPanel implements Map { try { prefs.flush(); } catch (Exception e) { - Logger.getLogger(PreferencesMap.class.getName()).log(Level.WARNING, e.toString()); + debug.log(Level.WARNING, e.toString()); } } diff --git a/source/net/filebot/util/SystemProperty.java b/source/net/filebot/util/SystemProperty.java index c49be43c..3e59786a 100644 --- a/source/net/filebot/util/SystemProperty.java +++ b/source/net/filebot/util/SystemProperty.java @@ -1,8 +1,9 @@ package net.filebot.util; +import static net.filebot.Logging.*; + import java.util.function.Function; import java.util.logging.Level; -import java.util.logging.Logger; public class SystemProperty { @@ -31,7 +32,7 @@ public class SystemProperty { try { return valueFunction.apply(prop); } catch (Exception e) { - Logger.getLogger(SystemProperty.class.getName()).logp(Level.WARNING, SystemProperty.class.getName(), key, e.toString()); + debug.logp(Level.WARNING, SystemProperty.class.getName(), key, e.toString()); } } diff --git a/source/net/filebot/util/Timer.java b/source/net/filebot/util/Timer.java index eb3490cf..c8e2ac17 100644 --- a/source/net/filebot/util/Timer.java +++ b/source/net/filebot/util/Timer.java @@ -1,11 +1,12 @@ package net.filebot.util; +import static net.filebot.Logging.*; + import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.logging.Level; -import java.util.logging.Logger; public abstract class Timer implements Runnable { @@ -33,7 +34,7 @@ public abstract class Timer implements Runnable { addShutdownHook(); } catch (Exception e) { // may fail if running with restricted permissions - Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getClass().getName() + ": " + e.getMessage()); + debug.log(Level.WARNING, e.getClass().getName() + ": " + e.getMessage()); } // remove shutdown hook after execution @@ -54,7 +55,7 @@ public abstract class Timer implements Runnable { removeShutdownHook(); } catch (Exception e) { // may fail if running with restricted permissions - Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getClass().getName() + ": " + e.getMessage()); + debug.log(Level.WARNING, e.getClass().getName() + ": " + e.getMessage()); } } diff --git a/source/net/filebot/util/ui/LinkButton.java b/source/net/filebot/util/ui/LinkButton.java index 2de97502..e7d74c76 100644 --- a/source/net/filebot/util/ui/LinkButton.java +++ b/source/net/filebot/util/ui/LinkButton.java @@ -1,5 +1,7 @@ package net.filebot.util.ui; +import static net.filebot.Logging.*; + import java.awt.Color; import java.awt.Cursor; import java.awt.Desktop; @@ -9,7 +11,6 @@ import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.net.URI; import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.AbstractAction; import javax.swing.Action; @@ -107,7 +108,7 @@ public class LinkButton extends JButton { } } catch (Exception e) { // should not happen - Logger.getLogger(getClass().getName()).log(Level.SEVERE, e.toString(), e); + debug.log(Level.SEVERE, e.toString(), e); } } } diff --git a/source/net/filebot/web/AcoustIDClient.java b/source/net/filebot/web/AcoustIDClient.java index ffc72111..a558638f 100644 --- a/source/net/filebot/web/AcoustIDClient.java +++ b/source/net/filebot/web/AcoustIDClient.java @@ -1,6 +1,7 @@ package net.filebot.web; import static java.nio.charset.StandardCharsets.*; +import static net.filebot.Logging.*; import static net.filebot.util.JsonUtilities.*; import static net.filebot.web.WebRequest.*; @@ -22,7 +23,6 @@ import java.util.Objects; import java.util.Scanner; import java.util.concurrent.TimeUnit; import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.Icon; @@ -171,7 +171,7 @@ public class AcoustIDClient implements MusicIdentificationService { return null; }).filter(Objects::nonNull).findFirst().orElse(audioTrack); // default to simple music info if extended info is not available } catch (Exception e) { - Logger.getLogger(AcoustIDClient.class.getName()).log(Level.WARNING, e.getMessage(), e); + debug.log(Level.WARNING, e.getMessage(), e); return null; } }).filter(Objects::nonNull).sorted(new MostFieldsNotNull()).findFirst().get(); @@ -241,7 +241,7 @@ public class AcoustIDClient implements MusicIdentificationService { } } } catch (Exception e) { - Logger.getLogger(AcoustIDClient.class.getName()).log(Level.WARNING, e.toString(), e); + debug.log(Level.WARNING, e.toString(), e); } return n; } diff --git a/source/net/filebot/web/AnidbClient.java b/source/net/filebot/web/AnidbClient.java index de08f88c..126bd3b4 100644 --- a/source/net/filebot/web/AnidbClient.java +++ b/source/net/filebot/web/AnidbClient.java @@ -1,6 +1,7 @@ package net.filebot.web; import static java.util.Collections.*; +import static net.filebot.Logging.*; import static net.filebot.util.StringUtilities.*; import static net.filebot.util.XPathUtilities.*; import static net.filebot.web.EpisodeUtilities.*; @@ -23,7 +24,6 @@ import java.util.Scanner; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -175,7 +175,7 @@ public class AnidbClient extends AbstractEpisodeListProvider { // sanity check if (episodes.isEmpty()) { // anime page xml doesn't work sometimes - Logger.getLogger(AnidbClient.class.getName()).log(Level.WARNING, String.format("Unable to parse episode data: %s (%d): %s", anime, anime.getAnimeId(), getXmlString(dom, false).split("\n", 2)[0].trim())); + debug.log(Level.WARNING, String.format("Unable to parse episode data: %s (%d): %s", anime, anime.getAnimeId(), getXmlString(dom, false).split("\n", 2)[0].trim())); } return new SeriesData(seriesInfo, episodes); diff --git a/source/net/filebot/web/ID3Lookup.java b/source/net/filebot/web/ID3Lookup.java index b5407730..f020af26 100644 --- a/source/net/filebot/web/ID3Lookup.java +++ b/source/net/filebot/web/ID3Lookup.java @@ -1,5 +1,6 @@ package net.filebot.web; +import static net.filebot.Logging.*; import static net.filebot.util.StringUtilities.*; import java.io.File; @@ -8,7 +9,6 @@ import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.Icon; @@ -63,7 +63,7 @@ public class ID3Lookup implements MusicIdentificationService { info.put(f, new AudioTrack(artist, title, album, albumArtist, trackTitle, albumReleaseDate, mediumIndex, mediumCount, trackIndex, trackCount, mbid)); } } catch (Throwable e) { - Logger.getLogger(ID3Lookup.class.getName()).log(Level.WARNING, e.toString()); + debug.log(Level.WARNING, e.toString()); } finally { mediaInfo.close(); } diff --git a/source/net/filebot/web/OpenSubtitlesClient.java b/source/net/filebot/web/OpenSubtitlesClient.java index a44b7cb0..812b470d 100644 --- a/source/net/filebot/web/OpenSubtitlesClient.java +++ b/source/net/filebot/web/OpenSubtitlesClient.java @@ -21,7 +21,6 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.function.Function; import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.Icon; @@ -368,7 +367,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS try { sublanguageid = getSubLanguageID(languageName, true); } catch (Exception e) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, e.getMessage(), e); + debug.log(Level.WARNING, e.getMessage(), e); } } diff --git a/source/net/filebot/web/OpenSubtitlesXmlRpc.java b/source/net/filebot/web/OpenSubtitlesXmlRpc.java index f5ad40de..320915cc 100644 --- a/source/net/filebot/web/OpenSubtitlesXmlRpc.java +++ b/source/net/filebot/web/OpenSubtitlesXmlRpc.java @@ -1,6 +1,7 @@ package net.filebot.web; import static java.util.Collections.*; +import static net.filebot.Logging.*; import static net.filebot.util.StringUtilities.*; import java.io.ByteArrayInputStream; @@ -20,7 +21,6 @@ import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.Scanner; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.DeflaterInputStream; @@ -134,7 +134,7 @@ public class OpenSubtitlesXmlRpc { movies.add(new SubtitleSearchResult(Integer.parseInt(imdbid), name, year, null, -1)); } catch (Exception e) { - Logger.getLogger(OpenSubtitlesXmlRpc.class.getName()).log(Level.FINE, String.format("Ignore movie [%s]: %s", movie, e.getMessage())); + debug.log(Level.FINE, String.format("Ignore movie [%s]: %s", movie, e.getMessage())); } } @@ -157,7 +157,7 @@ public class OpenSubtitlesXmlRpc { return new Movie(name, year, imdbid, -1); } catch (RuntimeException e) { // ignore, invalid response - Logger.getLogger(getClass().getName()).log(Level.WARNING, String.format("Failed to lookup movie by imdbid %s: %s", imdbid, e.getMessage())); + debug.log(Level.WARNING, String.format("Failed to lookup movie by imdbid %s: %s", imdbid, e.getMessage())); } return null; @@ -296,7 +296,7 @@ public class OpenSubtitlesXmlRpc { movieHashMap.put(hash, matches.get(0)); } else if (matches.size() > 1) { // multiple hash matches => ignore all - Logger.getLogger(getClass().getName()).log(Level.WARNING, "Ignore hash match due to hash collision: " + matches); + debug.log(Level.WARNING, "Ignore hash match due to hash collision: " + matches); } } } diff --git a/source/net/filebot/web/TMDbClient.java b/source/net/filebot/web/TMDbClient.java index b7b960fc..264c4702 100644 --- a/source/net/filebot/web/TMDbClient.java +++ b/source/net/filebot/web/TMDbClient.java @@ -26,7 +26,6 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Stream; @@ -163,7 +162,7 @@ public class TMDbClient implements MovieIdentificationService { return getMovieInfo(String.format("tt%07d", movie.getImdbId()), locale, extendedInfo); } } catch (FileNotFoundException | NullPointerException e) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, String.format("Movie data not found: %s [%d / %d]", movie, movie.getTmdbId(), movie.getImdbId())); + debug.log(Level.WARNING, String.format("Movie data not found: %s [%d / %d]", movie, movie.getTmdbId(), movie.getImdbId())); } return null; } diff --git a/source/net/filebot/web/TheTVDBClient.java b/source/net/filebot/web/TheTVDBClient.java index d114dd14..9d63890f 100644 --- a/source/net/filebot/web/TheTVDBClient.java +++ b/source/net/filebot/web/TheTVDBClient.java @@ -21,7 +21,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Random; import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.Icon; @@ -107,7 +106,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider { String seriesName = getTextContent("SeriesName", node); if (seriesName.startsWith("**") && seriesName.endsWith("**")) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, String.format("Invalid series: %s [%d]", seriesName, sid)); + debug.log(Level.WARNING, String.format("Invalid series: %s [%d]", seriesName, sid)); continue; } diff --git a/source/net/filebot/web/WebRequest.java b/source/net/filebot/web/WebRequest.java index f90b6c52..ec14219c 100644 --- a/source/net/filebot/web/WebRequest.java +++ b/source/net/filebot/web/WebRequest.java @@ -1,6 +1,7 @@ package net.filebot.web; import static java.nio.charset.StandardCharsets.*; +import static net.filebot.Logging.*; import static net.filebot.util.FileUtilities.*; import java.io.ByteArrayOutputStream; @@ -28,7 +29,6 @@ import java.util.Map; import java.util.Map.Entry; import java.util.function.Supplier; import java.util.logging.Level; -import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; @@ -279,7 +279,7 @@ public final class WebRequest { try { return Charset.forName(matcher.group(1)); } catch (IllegalArgumentException e) { - Logger.getLogger(WebRequest.class.getName()).log(Level.WARNING, "Illegal charset: " + contentType); + debug.log(Level.WARNING, "Illegal charset: " + contentType); } }