I am not yet sure wether the following is a useful idiom for logging of exceptions. It may depend on the special case of the software you are writing. It’s worth to think about logging because good logging can make a developer’s life much easier and not only for debugging purposes!
if(LOG.isDebugEnabled()){ LOG.error("An exception was thrown, see stacktrace",e); } else { LOG.error("An exception was thrown .... message bla"); }
I need this in a case where in debugging mode I would really like to keep stacktraces but I have no influence how logging is configured in the production environment and I am not allowed to log ‘multi-line’ statements like stacktraces.
I know it’s not a big thing, but logging like many other details is often treated like a hated step-child. If you spend some time with it, it will return your love and it will be a worthwhile experience to play with it 🙂