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
This commit is contained in:
4pr0n 2015-01-11 05:11:10 -08:00
parent dd55cd1b43
commit 083cd8d7cc
8 changed files with 29 additions and 18 deletions

View File

@ -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.

View File

@ -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();
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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();
}

View File

@ -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

View File

@ -333,6 +333,9 @@ public class Utils {
PropertyConfigurator.configure(stream);
}
logger.info("Loaded " + logFile);
try {
stream.close();
} catch (IOException e) { }
}
/**

View File

@ -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