Unify gui/console logging
This commit is contained in:
parent
f45f390d5c
commit
96b653da0a
|
@ -29,6 +29,7 @@ import java.security.Permissions;
|
||||||
import java.security.Policy;
|
import java.security.Policy;
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.logging.Handler;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
@ -187,7 +188,11 @@ public class Main {
|
||||||
try {
|
try {
|
||||||
// GUI logging settings
|
// GUI logging settings
|
||||||
log.addHandler(new NotificationHandler(getApplicationName()));
|
log.addHandler(new NotificationHandler(getApplicationName()));
|
||||||
log.addHandler(createSimpleFileHandler(new File(getApplicationFolder(), "error.log"), Level.WARNING)); // only log errors to file
|
|
||||||
|
// log errors to file
|
||||||
|
Handler error = createSimpleFileHandler(new File(getApplicationFolder(), "error.log"), Level.WARNING);
|
||||||
|
log.addHandler(error);
|
||||||
|
debug.addHandler(error);
|
||||||
|
|
||||||
// use native LaF an all platforms
|
// use native LaF an all platforms
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class NotificationHandler extends Handler {
|
||||||
this.timeout = timeout;
|
this.timeout = timeout;
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
|
|
||||||
setFormatter(new NotificationFormatter());
|
setFormatter(new SimpleMessageFormatter());
|
||||||
setLevel(Level.INFO);
|
setLevel(Level.INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,11 +69,15 @@ public class NotificationHandler extends Handler {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class NotificationFormatter extends Formatter {
|
public static class SimpleMessageFormatter extends Formatter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String format(LogRecord record) {
|
public String format(LogRecord record) {
|
||||||
return record.getMessage();
|
String message = record.getMessage();
|
||||||
|
if (message == null && record.getThrown() != null) {
|
||||||
|
message = record.getThrown().toString();
|
||||||
|
}
|
||||||
|
return message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue