change removes log of the stack trace for exceptions
Description
Environment
Activity
Brad Johnson November 30, 2004 at 5:39 PM
You can just change everywhere that the log prints an exception for an error to
pass it in as the second parameter to log() instead of contatinating it. This
will print the stack trace with line numbers (which includes the current method
name) which is important to track down errors.
Please change these:
LogService.log(LogService.ERROR,"CBookmarks.getConnection() "+ e);
to at least this:
LogService.log(LogService.ERROR,"CBookmarks.getConnection() ", e);
or to be most concise this:
LogService.log(LogService.ERROR,e);
Here's a patch that does the most conservative change:
Index: CBookmarks.java
===================================================================
RCS file:
/home/cvs/jasig/portal_channels/Bookmarks/source/org/jasig/portal/channels/bookmarks/CBookmarks.java,v
retrieving revision 1.12
diff -u -r1.12 CBookmarks.java
— CBookmarks.java 30 Nov 2004 16:27:24 -0000 1.12
+++ CBookmarks.java 30 Nov 2004 16:37:17 -0000
@@ -283,7 +283,7 @@
stmt.close();
}
} catch (Exception e) {
LogService.log(LogService.ERROR,"CBookmarks.getDefaultBookmarks():
Exception:"+ e);
+ LogService.log(LogService.ERROR,"CBookmarks.getDefaultBookmarks():
Exception:", e);
} finally {
if (connection != null) {
releaseConnection(connection);
@@ -333,7 +333,7 @@
ps.close();
}
} catch (Exception e) {LogService.log(LogService.ERROR,"CBookmarks.saveXML() "+ e);
+ LogService.log(LogService.ERROR,"CBookmarks.saveXML() ", e);
} finally {
releaseConnection(connection);
}
@@ -690,7 +690,7 @@
break;
}
} catch (Exception e) {LogService.log(LogService.ERROR,"CBookmarks.renderXML() "+ e);
+ LogService.log(LogService.ERROR,"CBookmarks.renderXML() ", e);
}
}
@@ -965,7 +965,7 @@
// return (rdbmServices.getConnection());
return (getRDBMServices().getConnection());
} catch (Exception e) {
LogService.log(LogService.ERROR,"CBookmarks.getConnection() "+ e);
+ LogService.log(LogService.ERROR,"CBookmarks.getConnection() ", e);
return (null);
}
}
@@ -977,7 +977,7 @@
// rdbmServices.releaseConnection(connection);
getRDBMServices().releaseConnection(connection);
} catch (Exception e) {LogService.log(LogService.ERROR,"CBookmarks.releaseConnection() "+ e);
+ LogService.log(LogService.ERROR,"CBookmarks.releaseConnection() ", e);
}
}
John Fereira November 30, 2004 at 4:44 PM
I could not find the specific logging message in which the stack trace was not
included.
As far as including the class/method name in the message I personally find it
much easier to track down problems if they are included. I'm not sure it's
really worth the effort to remove the class/method names in the log messages.
Brad Johnson November 23, 2004 at 10:32 PM
Basically you don't need to include the class/method in the log
string if you have the stack trace.
It's shorter to code, easier to read the code and easier to find out exactly
where the problem was if you just write a stack trace.
Change committed on 2004/11/19 to version 1.11 of Bookmarks.java undid fix to
log messages that allows the stack trace to be logged if there is an error.
Stack traces should be logged if there is an exception thrown.
This:
LogService.instance().log(LogService.ERROR, e);
Was replaced with this:
LogService.instance().log(LogService.ERROR,"CBookmarks.getDefaultBookmarks():
Exception:"+ e);
This change should be undone. See:
http://tp.its.yale.edu/uPortal/tiki-index.php?page=Code+Best+Practices