Description:
|
When a logging statement occurs using an extending class, in my case, XLogger, with a parameterized query, on a LocationAwareLogger, the LoggerWrapper will use the MessageFormatter, format the message, and then pass it onto the bounded logger with null as the throwable. The MessageFormatter has already identified the exception, if applicable, and parsed it out of the object list. It has also generated an object list for the remaining objects. In my case, the underlying logged, log4j12, simply ignored the object list, used the formatted string, and saw null for the exception.
Attached is a very simple example (with pom and log4j.properties file) to demonstrate the problem.
package demo.slf4j.ext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.ext.XLogger;
public class LoggerWrapperFailureDemo
{
static XLogger logger = new XLogger(LoggerFactory.getLogger(LoggerWrapperFailureDemo.class));
static Logger traditional = LoggerFactory.getLogger(LoggerWrapperFailureDemo.class);
public static void main( String[] args )
{
Exception e = new Exception("foo", new Exception("bar"));
logger.warn( "No Param", e);
logger.warn( "Param: {}", "etc", e);
traditional.warn( "No XLogger (So No LoggerWrapper {} ", "etc", e);
}
}
Here you will see the first (no parameter) and third (no loggerWrapper) log statements show the exception/stacktrace, however the second one fails.
Interestingly, this code was written in a way that worked for a couple of the debug functions, but had this problem in the majority of the LoggerWrapper class
|