diff --git a/src/tap/log/DefaultTAPLog.java b/src/tap/log/DefaultTAPLog.java index 8374bed467ee155b3715f48c8509d12d035b56aa..90cbeba0baa2ff99082cc2facc6aa353c7ef84b0 100644 --- a/src/tap/log/DefaultTAPLog.java +++ b/src/tap/log/DefaultTAPLog.java @@ -96,12 +96,12 @@ public class DefaultTAPLog extends DefaultUWSLog implements TAPLog { if (error.getCause() != null) printException(error.getCause(), out); else{ - out.println("Caused by a " + error.getClass().getName()); + out.println("Caused by a " + error.getClass().getName() + " " + getExceptionOrigin(error)); if (error.getMessage() != null) out.println("\t" + error.getMessage()); } }else if (error instanceof SQLException){ - out.println("Caused by a " + error.getClass().getName()); + out.println("Caused by a " + error.getClass().getName() + " " + getExceptionOrigin(error)); out.print("\t"); do{ out.println(error.getMessage()); diff --git a/src/uws/service/log/DefaultUWSLog.java b/src/uws/service/log/DefaultUWSLog.java index a4e0129a3bd4c4015eb0dec6c37427960934d4bb..637b022f487fcf962018162be3e0f42ea94cf76e 100644 --- a/src/uws/service/log/DefaultUWSLog.java +++ b/src/uws/service/log/DefaultUWSLog.java @@ -346,11 +346,28 @@ public class DefaultUWSLog implements UWSLog { } /** - * Format and print the given exception inside the given writer. + * <p>Format and print the given exception inside the given writer.</p> + * + * <p>This function does nothing if the given error is NULL.</p> + * + * <p>The full stack trace is printed ONLY for unknown exceptions.</p> + * + * <p>The printed text has the following format for known exceptions:</p> + * <pre> + * Caused by a {ExceptionClassName} {ExceptionOrigin} + * {ExceptionMessage} + * </pre> + * + * <p>The printed text has the following format for unknown exceptions:</p> + * <pre> + * Caused by a {ExceptionFullStackTrace} + * </pre> * * @param error The exception to print. * @param out The output in which the exception must be written. * + * @see #getExceptionOrigin(Throwable) + * * @since 4.1 */ protected void printException(final Throwable error, final PrintWriter out){ @@ -359,7 +376,7 @@ public class DefaultUWSLog implements UWSLog { if (error.getCause() != null) printException(error.getCause(), out); else{ - out.println("Caused by a " + error.getClass().getName()); + out.println("Caused by a " + error.getClass().getName() + " " + getExceptionOrigin(error)); if (error.getMessage() != null) out.println("\t" + error.getMessage()); } @@ -370,6 +387,33 @@ public class DefaultUWSLog implements UWSLog { } } + /** + * <p>Format and return the origin of the given error. + * "Origin" means here: "where the error has been thrown from?" (from which class? method? file? line?).</p> + * + * <p>This function does nothing if the given error is NULL or if the origin information is missing.</p> + * + * <p>The returned text has the following format:</p> + * <pre> + * at {OriginClass}.{OriginMethod}({OriginFile}:{OriginLine}) + * </pre> + * + * <p>{OriginFile} and {OriginLine} are written only if provided.</p> + * + * @param error Error whose the origin should be returned. + * + * @return A string which contains formatted information about the origin of the given error. + * + * @since 4.1 + */ + protected String getExceptionOrigin(final Throwable error){ + if (error != null && error.getStackTrace() != null && error.getStackTrace().length > 0){ + StackTraceElement src = error.getStackTrace()[0]; + return "at " + src.getClassName() + "." + src.getMethodName() + ((src.getFileName() != null) ? "(" + src.getFileName() + ((src.getLineNumber() >= 0) ? ":" + src.getLineNumber() : "") + ")" : ""); + }else + return ""; + } + @Override public void debug(String msg){ log(LogLevel.DEBUG, null, msg, null);