On Sep 16, 2011, at 10:32 AM, Scott Deboy wrote:
> Does it help to provide the Throwable as the first argument? That's what
> some of the overloaded LogSF/MF methods do to avoid ambiguity, if I recall.
Putting the Throwable before the argument array does help. Unfortunately it
also makes bridging an API such as the one below from SLF4J a bit harder.
public void error(Marker marker, String s, Object[] objects) {
if (isErrorEnabled(marker)) {
log((org.apache.logging.log4j.Marker) marker, FQCN, Level.ERROR,
new ParameterizedMessage(s, objects), null);
}
}
Since SLF4J doesn't include an explicit Throwable we would need to do
public void error(Marker marker, String s, Object[] objects) {
if (isErrorEnabled(marker)) {
Object[] arrary;
Throwable t = null;
if (objects == null || objects.length == 0) {
array = objects;
} else if (objects[objects.length - 1] instanceof Throwable) {
t = objects[objects.length - 1];
array = new Object[object.length -1];
System.arraycopy(objects, 0, array, 0, objects.length - 1);
}
log((org.apache.logging.log4j.Marker) marker, FQCN, Level.ERROR,
new ParameterizedMessage(s, array), t);
}
}
Currently parameterized message determines whether the last argument is a
Throwable. As John has pointed out though, it is being ignored when the
LogEvent is created and by Layouts, etc.
Ralph
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]