Skip to content
Snippets Groups Projects
Commit a76a7b99 authored by gmantele's avatar gmantele
Browse files

[UWS,TAP] Add the origin of the main exception after the exception class name...

[UWS,TAP] Add the origin of the main exception after the exception class name in the log entries. This origin includes the class, the method, the file and the line where the exception has been thrown.
parent 89757f72
No related branches found
No related tags found
No related merge requests found
......@@ -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());
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment