Refactor warning messages

This commit is contained in:
Reinhard Pointner 2017-02-01 16:10:01 +08:00
parent ae8f7e0846
commit 343f6de4db
5 changed files with 24 additions and 21 deletions

View File

@ -1,6 +1,7 @@
package net.filebot;
import static java.nio.channels.Channels.*;
import static net.filebot.util.ExceptionUtilities.*;
import java.io.File;
import java.io.FileOutputStream;
@ -95,6 +96,15 @@ public final class Logging {
};
}
public static Supplier<String> cause(Throwable t) {
return () -> {
StringBuilder s = new StringBuilder();
s.append(t.getClass().getSimpleName()).append(": ");
s.append(t.getMessage());
return s.toString();
};
}
public static class ConsoleFormatter extends Formatter {
private final Pattern anonymize;

View File

@ -153,7 +153,7 @@ public abstract class ScriptShellBaseClass extends Script {
if (severe) {
log.log(Level.SEVERE, trace(t));
} else {
log.log(Level.WARNING, format("%s: %s", t.getClass().getSimpleName(), t.getMessage()));
log.log(Level.WARNING, cause(t));
}
}

View File

@ -93,7 +93,7 @@ class RenameAction extends AbstractAction {
} catch (CancellationException e) {
debug.finest(e::toString);
} catch (Throwable e) {
log.log(Level.SEVERE, String.format("%s: %s", getRootCause(e).getClass().getSimpleName(), getRootCauseMessage(e)), e);
log.log(Level.SEVERE, e, cause(getRootCause(e)));
}
// abort if nothing happened

View File

@ -643,7 +643,7 @@ public class RenamePanel extends JComponent {
// show and block
dialog.setVisible(true);
} catch (Exception e) {
log.log(Level.WARNING, String.format("%s: %s", getRootCause(e).getClass().getSimpleName(), getRootCauseMessage(e)), e);
log.log(Level.WARNING, e, cause(getRootCause(e)));
}
});
@ -917,10 +917,7 @@ public class RenamePanel extends JComponent {
}
// generic error message
if (findCause(e, CancellationException.class) == null) {
log.log(Level.WARNING, String.format("%s: %s", getRootCause(e).getClass().getSimpleName(), getRootCauseMessage(e)), e);
return;
}
log.log(Level.WARNING, e, cause(getRootCause(e)));
} finally {
// auto-match finished
namesList.firePropertyChange(LOADING_PROPERTY, true, false);

View File

@ -173,21 +173,17 @@ class SubtitleAutoMatchDialog extends JDialog {
component.setBorder(BorderFactory.createEmptyBorder());
component.setVisible(false);
service.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (service.getState() == StateValue.STARTED) {
component.setIcon(ResourceManager.getIcon("database.go"));
} else {
component.setIcon(ResourceManager.getIcon(service.getError() == null ? "database.ok" : "database.error"));
}
component.setVisible(true);
component.setToolTipText(String.format("%s: %s", service.getName(), service.getError() == null ? service.getState().toString().toLowerCase() : service.getError().getMessage()));
servicePanel.setVisible(true);
servicePanel.getParent().revalidate();
service.addPropertyChangeListener(evt -> {
if (service.getState() == StateValue.STARTED) {
component.setIcon(ResourceManager.getIcon("database.go"));
} else {
component.setIcon(ResourceManager.getIcon(service.getError() == null ? "database.ok" : "database.error"));
}
component.setVisible(true);
component.setToolTipText(String.format("%s: %s", service.getName(), service.getError() == null ? service.getState().toString().toLowerCase() : service.getError().getMessage()));
servicePanel.setVisible(true);
servicePanel.getParent().revalidate();
});
services.add(service);