From b40638f472ea01d295046f35205c1982d836e092 Mon Sep 17 00:00:00 2001 From: gmantele <gmantele@ari.uni-heidelberg.de> Date: Tue, 23 Sep 2014 17:31:59 +0200 Subject: [PATCH] [TAP,UWS] Small log corrections (for Thread logs, display the thread name rather than the ID ; the job id was forgotten in the log of CHANGE_PHASE ; build a UWSException with the given throwable message as message ; in log TAP for the event EXECUTING, the memory address of the ADQLQuery object was displayed rather than of the ADQL query expression ; display the stack trace of the SQLException.getNextException() when calling logDB) --- src/tap/ADQLExecutor.java | 2 +- src/tap/log/DefaultTAPLog.java | 12 ++++++++++++ src/uws/UWSException.java | 4 ++-- src/uws/job/UWSJob.java | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/tap/ADQLExecutor.java b/src/tap/ADQLExecutor.java index 8ad271f..96f18fc 100644 --- a/src/tap/ADQLExecutor.java +++ b/src/tap/ADQLExecutor.java @@ -530,7 +530,7 @@ public class ADQLExecutor { */ protected TableIterator executeADQL(final ADQLQuery adql) throws InterruptedException, TAPException{ // Log the start of execution: - logger.logTAP(LogLevel.INFO, report, "EXECUTING", "Executing ADQL: " + adql.toString().replaceAll("(\t|\r?\n)+", " "), null); + logger.logTAP(LogLevel.INFO, report, "EXECUTING", "Executing ADQL: " + adql.toADQL().replaceAll("(\t|\r?\n)+", " "), null); // Execute the ADQL query: TableIterator result = dbConn.executeQuery(adql); diff --git a/src/tap/log/DefaultTAPLog.java b/src/tap/log/DefaultTAPLog.java index 441a8f0..f20e6fa 100644 --- a/src/tap/log/DefaultTAPLog.java +++ b/src/tap/log/DefaultTAPLog.java @@ -22,6 +22,7 @@ package tap.log; import java.io.OutputStream; import java.io.PrintWriter; +import java.sql.SQLException; import tap.TAPExecutionReport; import tap.TAPSyncJob; @@ -88,7 +89,18 @@ public class DefaultTAPLog extends DefaultUWSLog implements TAPLog { @Override public void logDB(final LogLevel level, final DBConnection connection, final String event, final String message, final Throwable error){ + // log the main given error: log(level, "DB", event, (connection != null ? connection.getID() : null), message, error); + + /* Some SQL exceptions (like BatchUpdateException) have a next exception which provides more information. + * Here, the stack trace of the next exception is also logged: + */ + if (error != null && error instanceof SQLException && ((SQLException)error).getNextException() != null){ + PrintWriter out = getOutput(level, "DB"); + out.println("[NEXT EXCEPTION]"); + ((SQLException)error).getNextException().printStackTrace(out); + out.flush(); + } } @Override diff --git a/src/uws/UWSException.java b/src/uws/UWSException.java index 0035960..1128170 100644 --- a/src/uws/UWSException.java +++ b/src/uws/UWSException.java @@ -139,7 +139,7 @@ public class UWSException extends Exception { * @param t The thrown (and so caught) exception. */ public UWSException(int httpError, Throwable t){ - this(httpError, t, null, null); + this(httpError, t, (t != null) ? t.getMessage() : null, null); } /** @@ -151,7 +151,7 @@ public class UWSException extends Exception { * @param type Type of the error (FATAL or TRANSIENT). <i>Note: If NULL, it will be considered as FATAL.</i> */ public UWSException(int httpError, Throwable t, ErrorType type){ - this(httpError, t, null, type); + this(httpError, t, (t != null) ? t.getMessage() : null, type); } /** diff --git a/src/uws/job/UWSJob.java b/src/uws/job/UWSJob.java index 088fbfd..c26bad8 100644 --- a/src/uws/job/UWSJob.java +++ b/src/uws/job/UWSJob.java @@ -575,7 +575,7 @@ public class UWSJob extends SerializableUWSObject { ExecutionPhase oldPhase = phase.getPhase(); phase.setPhase(p, force); - getLogger().logJob(LogLevel.INFO, this, "CHANGE_PHASE", "The job \"\" goes from " + oldPhase + " to " + p, null); + getLogger().logJob(LogLevel.INFO, this, "CHANGE_PHASE", "The job \"" + getJobId() + "\" goes from " + oldPhase + " to " + p, null); // Notify the execution manager: if (phase.isFinished() && getJobList() != null) -- GitLab