[slf4j-dev] Design of MessageFormatter

Boris Unckel boris.unckel.mlg at gmx.net
Thu Dec 29 20:24:23 CET 2005


Hello,

I had a mail conversation where the developer of another JUL-extension asked
whether my object handling (for Messages with objects or object/object[]
paramters) is exception safe or not.
He argues, a logging operation should never lead to an exception in the
using system, except the logging system itself is corrupt/misconfigured.
I had a look at my own code, it is currently not exception safe for object
handling, I have an idea how to solve it.

Different for the native slf4j implemementation:
I will not change the behaviour/code of the org.slf4j.impl.MessageFormatter
until discussed here.

The line is 150:
sbuf.append(argArray[L]);
What happens here is a null safe operation (OK):
String.valueOf(argArray[L]);
In case the toString Method throws an RuntimeException (due to bad code in
the using system) it will influence the whole logging operation (canceled),
and cause an error in the using system.

Two ways of solution:
1) Ignore it, the developer of the system is responsible for correct,
exception-free toString implementation of her objects.
I think this is bad, because this may occure in rare runtime situations and
awfully to detect.

2) Signal an error in the user log, giving a hint and a number to lookup for
detailed cause.
Log the detailed reason and number in the underlying log system, or in
x4juli case, in the internal log. (In depracted log4j terms LogLog).

I hope my description is good enough to understand the problem, please ask,
this is important for any implementation.

Opinions? Other solutions? No problem at all?

Regards
Boris



More information about the slf4j-dev mailing list