From 9585222dac6894e3faaca5c411922011b0e0ea33 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 13 May 2008 22:19:20 +0000 Subject: [PATCH] add exception logging git-svn-id: http://trooper/svn/projects/jSite/trunk@870 c3eda9e8-030b-0410-8277-bc7414b0a119 --- src/net/pterodactylus/util/logging/Logging.java | 27 +++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/net/pterodactylus/util/logging/Logging.java b/src/net/pterodactylus/util/logging/Logging.java index fe2fb54..ef8bb6a 100644 --- a/src/net/pterodactylus/util/logging/Logging.java +++ b/src/net/pterodactylus/util/logging/Logging.java @@ -91,10 +91,29 @@ public class Logging { @Override public synchronized String format(LogRecord record) { recordBuffer.setLength(0); - recordBuffer.append(dateFormatter.format(new Date(record.getMillis()))).append(' ').append(record.getLevel().getName()).append(' '); - recordBuffer.append(record.getSourceClassName()).append('.').append(record.getSourceMethodName()).append(' '); - recordBuffer.append(record.getMessage()); - recordBuffer.append("\r\n"); + String linePrefix = dateFormatter.format(new Date(record.getMillis())) + " [" + record.getLevel() + "] [" + Thread.currentThread().getName() + "] [" + record.getSourceClassName() + "." + record.getSourceMethodName() + "] "; + recordBuffer.append(linePrefix).append(record.getMessage()).append('\n'); + if (record.getThrown() != null) { + Throwable throwable = record.getThrown(); + boolean causedBy = false; + while (throwable != null) { + recordBuffer.append(linePrefix); + if (causedBy) { + recordBuffer.append("caused by: "); + } + recordBuffer.append(throwable.getClass().getName()); + if (throwable.getMessage() != null) { + recordBuffer.append(": ").append(throwable.getMessage()); + } + recordBuffer.append("\n"); + StackTraceElement[] stackTraceElements = throwable.getStackTrace(); + for (StackTraceElement stackTraceElement: stackTraceElements) { + recordBuffer.append(linePrefix).append(" at ").append(stackTraceElement.getClassName()).append('.').append(stackTraceElement.getMethodName()).append("(").append(stackTraceElement.getFileName()).append(':').append(stackTraceElement.getLineNumber()).append(')').append("\n"); + } + throwable = throwable.getCause(); + causedBy = true; + } + } return recordBuffer.toString(); } }); -- 2.7.4