Mittwoch, 23. September 2009
Today I had the problem that no stacktrace was printed in logs produced by log4j. Here's an important difference between the logging functions with 1 and 2 parameters:

Logger logger = Logger.getLogger(MyClass.class);
try {
  someFunction();
} catch(MyException e) {
  logger.error("someFunction failed", e); //   prints stacktrace
  logger.error("someFunction failed" + e); // one-liner with type of exception
}

So, use 2 parameters with the Throwable object as 2nd parameter to get a full backtrace. If you want to receive a single line in your output can pass the Throwable as the 1st parameter.