--- a/java/sql-dk/src/info/globalcode/sql/dk/ColorfulPrintWriter.java Wed Dec 25 01:23:27 2013 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/ColorfulPrintWriter.java Wed Dec 25 02:04:57 2013 +0100
@@ -79,6 +79,10 @@
}
private boolean colorful = true;
+ public void setStyle(TerminalStyle style) {
+ setStyle(EnumSet.of(style));
+ }
+
public void setStyle(EnumSet<TerminalStyle> styles) {
printCodes(getStyleCodes(styles));
}
--- a/java/sql-dk/src/info/globalcode/sql/dk/logging/ColorfulConsoleFormatter.java Wed Dec 25 01:23:27 2013 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/logging/ColorfulConsoleFormatter.java Wed Dec 25 02:04:57 2013 +0100
@@ -32,13 +32,15 @@
*/
public class ColorfulConsoleFormatter extends Formatter {
+ private boolean printStacktrace = false;
+
@Override
public String format(LogRecord r) {
StringWriter sw = new StringWriter();
try (ColorfulPrintWriter out = new ColorfulPrintWriter(sw)) {
printLevel(out, r.getLevel());
printMessage(out, r);
- printThrowable(out, r.getThrown());
+ printThrowable(out, r);
out.println();
}
return sw.toString();
@@ -46,7 +48,6 @@
private void printLevel(ColorfulPrintWriter out, Level l) {
TerminalColor color = TerminalColor.Magenta;
- TerminalStyle style;
if (l == Level.SEVERE) {
color = TerminalColor.Red;
@@ -61,7 +62,8 @@
out.print(formatMessage(r));
}
- private void printThrowable(ColorfulPrintWriter out, Throwable t) {
+ private void printThrowable(ColorfulPrintWriter out, LogRecord r) {
+ Throwable t = r.getThrown();
if (t != null) {
out.print(": ");
out.print(TerminalColor.Red, t.getClass().getSimpleName());
@@ -70,6 +72,21 @@
out.print(": ");
out.print(message);
}
+ if (printStacktrace) {
+ out.println();
+ out.setForegroundColor(TerminalColor.Yellow);
+ out.setStyle(TerminalStyle.Dim);
+ t.printStackTrace(out);
+ out.resetAll();
+ }
}
}
+
+ public boolean isPrintStacktrace() {
+ return printStacktrace;
+ }
+
+ public void setPrintStacktrace(boolean printStacktrace) {
+ this.printStacktrace = printStacktrace;
+ }
}
--- a/java/sql-dk/src/info/globalcode/sql/dk/logging/LoggerInitializer.java Wed Dec 25 01:23:27 2013 +0100
+++ b/java/sql-dk/src/info/globalcode/sql/dk/logging/LoggerInitializer.java Wed Dec 25 02:04:57 2013 +0100
@@ -43,7 +43,7 @@
logger.addHandler(handler);
handler.setFormatter(formatter);
- setLevel(logger, handler);
+ setLevel(logger, handler, formatter);
/**
@@ -51,7 +51,7 @@
*/
}
- private void setLevel(Logger logger, Handler handler) {
+ private void setLevel(Logger logger, Handler handler, ColorfulConsoleFormatter formatter) {
boolean levelParseError = false;
Level level;
String cliLevel = System.getProperty(LEVEL_PROPERTY);
@@ -72,5 +72,7 @@
if (levelParseError) {
log.log(Level.WARNING, "Invalid logging level „{0}“ specified in „{1}“ → using default level „{2}“", new Object[]{cliLevel, LEVEL_PROPERTY, DEFAULT_LEVEL});
}
+
+ formatter.setPrintStacktrace(level.intValue() < Level.INFO.intValue());
}
}