From 083cd8d7cc38d147059b8db37854857b288ac3d9 Mon Sep 17 00:00:00 2001 From: 4pr0n Date: Sun, 11 Jan 2015 05:11:10 -0800 Subject: [PATCH] Logger enhancements UI shows already-downloaded files as 'completed' instead of 'errored'. No more "Retrieving" lines in UI log window. WARN log levels all around. Mostly for #147 --- .../ripme/ripper/AbstractRipper.java | 2 +- .../rarchives/ripme/ripper/AlbumRipper.java | 8 ++++---- .../ripme/ripper/DownloadFileThread.java | 2 +- .../ripme/ripper/DownloadVideoThread.java | 2 +- .../rarchives/ripme/ripper/VideoRipper.java | 4 ++-- .../com/rarchives/ripme/ui/MainWindow.java | 20 +++++++++++++------ .../java/com/rarchives/ripme/utils/Utils.java | 3 +++ src/main/resources/log4j.file.properties | 6 +++--- 8 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java b/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java index d84adb4c..bedc371c 100644 --- a/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java @@ -198,7 +198,7 @@ public abstract class AbstractRipper * @param url * @param message */ - public abstract void downloadProblem(URL url, String message); + public abstract void downloadExists(URL url, File file); /** * @return Number of files downloaded. diff --git a/src/main/java/com/rarchives/ripme/ripper/AlbumRipper.java b/src/main/java/com/rarchives/ripme/ripper/AlbumRipper.java index 96031b1c..3b0a56c9 100644 --- a/src/main/java/com/rarchives/ripme/ripper/AlbumRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/AlbumRipper.java @@ -125,14 +125,14 @@ public abstract class AlbumRipper extends AbstractRipper { } @Override - public void downloadProblem(URL url, String message) { + public void downloadExists(URL url, File file) { if (observer == null) { return; } - + itemsPending.remove(url); - itemsErrored.put(url, message); - observer.update(this, new RipStatusMessage(STATUS.DOWNLOAD_WARN, url + " : " + message)); + itemsCompleted.put(url, file); + observer.update(this, new RipStatusMessage(STATUS.DOWNLOAD_WARN, url + " already saved as " + file.getAbsolutePath())); checkIfComplete(); } diff --git a/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java b/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java index 9256c2be..319e504b 100644 --- a/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java +++ b/src/main/java/com/rarchives/ripme/ripper/DownloadFileThread.java @@ -73,7 +73,7 @@ public class DownloadFileThread extends Thread { saveAs.delete(); } else { logger.info("[!] Skipping " + url + " -- file already exists: " + prettySaveAs); - observer.downloadProblem(url, "File already exists: " + prettySaveAs); + observer.downloadExists(url, saveAs); return; } } diff --git a/src/main/java/com/rarchives/ripme/ripper/DownloadVideoThread.java b/src/main/java/com/rarchives/ripme/ripper/DownloadVideoThread.java index 8e4d1e56..7675c89e 100644 --- a/src/main/java/com/rarchives/ripme/ripper/DownloadVideoThread.java +++ b/src/main/java/com/rarchives/ripme/ripper/DownloadVideoThread.java @@ -56,7 +56,7 @@ public class DownloadVideoThread extends Thread { saveAs.delete(); } else { logger.info("[!] Skipping " + url + " -- file already exists: " + prettySaveAs); - observer.downloadProblem(url, "File already exists: " + prettySaveAs); + observer.downloadExists(url, saveAs); return; } } diff --git a/src/main/java/com/rarchives/ripme/ripper/VideoRipper.java b/src/main/java/com/rarchives/ripme/ripper/VideoRipper.java index f1263673..e45e89f3 100644 --- a/src/main/java/com/rarchives/ripme/ripper/VideoRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/VideoRipper.java @@ -111,11 +111,11 @@ public abstract class VideoRipper extends AbstractRipper { checkIfComplete(); } @Override - public void downloadProblem(URL url, String message) { + public void downloadExists(URL url, File file) { if (observer == null) { return; } - observer.update(this, new RipStatusMessage(STATUS.DOWNLOAD_WARN, url + " : " + message)); + observer.update(this, new RipStatusMessage(STATUS.DOWNLOAD_WARN, url + " already saved as " + file)); checkIfComplete(); } diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index ffc148b8..70ee8f2d 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -60,6 +60,7 @@ import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; +import org.apache.log4j.Level; import org.apache.log4j.Logger; import com.rarchives.ripme.ripper.AbstractRipper; @@ -139,6 +140,7 @@ public class MainWindow implements Runnable, RipStatusHandler { private static AbstractRipper ripper; public MainWindow() { + Logger.getRootLogger().setLevel(Level.ERROR); mainFrame = new JFrame("RipMe v" + UpdateUtils.getThisJarVersion()); mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainFrame.setResizable(false); @@ -1021,20 +1023,26 @@ public class MainWindow implements Runnable, RipStatusHandler { switch(msg.getStatus()) { case LOADING_RESOURCE: case DOWNLOAD_STARTED: - appendLog( "Downloading: " + (String) msg.getObject(), Color.BLACK); + if (logger.isEnabledFor(Level.INFO)) { + appendLog( "Downloading " + (String) msg.getObject(), Color.BLACK); + } break; case DOWNLOAD_COMPLETE: - appendLog( "Completed: " + (String) msg.getObject(), Color.GREEN); + appendLog( "Downloaded " + (String) msg.getObject(), Color.GREEN); break; case DOWNLOAD_ERRORED: - appendLog( "Error: " + (String) msg.getObject(), Color.RED); + if (logger.isEnabledFor(Level.ERROR)) { + appendLog((String) msg.getObject(), Color.RED); + } break; case DOWNLOAD_WARN: - appendLog( "Warn: " + (String) msg.getObject(), Color.ORANGE); + appendLog((String) msg.getObject(), Color.ORANGE); break; case RIP_ERRORED: - appendLog( "Error: " + (String) msg.getObject(), Color.RED); + if (logger.isEnabledFor(Level.ERROR)) { + appendLog((String) msg.getObject(), Color.RED); + } stopButton.setEnabled(false); statusProgress.setValue(0); statusProgress.setVisible(false); @@ -1079,7 +1087,7 @@ public class MainWindow implements Runnable, RipStatusHandler { Image folderIcon = ImageIO.read(getClass().getClassLoader().getResource("folder.png")); openButton.setIcon(new ImageIcon(folderIcon)); } catch (Exception e) { } - appendLog( "Rip complete, saved to " + prettyFile, Color.GREEN); + appendLog( "Rip complete, saved to " + f.getAbsolutePath(), Color.GREEN); openButton.setActionCommand(f.toString()); openButton.addActionListener(new ActionListener() { @Override diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index c51de33e..aaf96402 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -333,6 +333,9 @@ public class Utils { PropertyConfigurator.configure(stream); } logger.info("Loaded " + logFile); + try { + stream.close(); + } catch (IOException e) { } } /** diff --git a/src/main/resources/log4j.file.properties b/src/main/resources/log4j.file.properties index 26752ead..3bb9d65d 100644 --- a/src/main/resources/log4j.file.properties +++ b/src/main/resources/log4j.file.properties @@ -2,15 +2,15 @@ log4j.appender.FILE = org.apache.log4j.RollingFileAppender log4j.appender.FILE.File = ripme.log log4j.appender.FILE.ImmediateFlush = true -log4j.appender.FILE.Threshold = debug +log4j.appender.FILE.Threshold = warn log4j.appender.FILE.maxFileSize = 20MB log4j.appender.FILE.layout = org.apache.log4j.PatternLayout -log4j.appender.FILE.layout.ConversionPattern = %d %-4r [%t] %-5p %c{2} %x - %m%n +log4j.appender.FILE.layout.ConversionPattern = %d %-5p %c{2} %x - %m%n # define the console appender log4j.appender.stdout = org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target = System.out -log4j.appender.stdout.Threshold = info +log4j.appender.stdout.Threshold = warn log4j.appender.stdout.layout = org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern = %m%n