I’ve got a J2EE web application that I’m working on and when an exception occurs, I’d like to get some basic details about the exception and log it. The message that I’m logging should be pretty basic, something that might mean something to the people running the web server(s).
Would using e.getMessage() be the best thing to log? Thanks.
I default to getting the whole stacktrace, that way I can see more of the context of what was going on when the error occurred.
If you use log4j and pass the exception into one of its logging methods it will print whatever message you give it, plus the exception’s message and its stacktrace for you:
If you have error-prone things like calls to web services, you could wrap exceptions thrown in an exception that you assign a very clear message to, so when the admins see it that message will tell them what’s going on.
For that matter, you could keep separate logs, one with stacktraces for the developers and another that you write admin-friendly messages to. You could have an exception handler that tries to map the exception to a friendly message, then write that message to an admin log.