[slf4j-user] separation of format and data

Ed Bras zooi at debrasjes.com
Mon Aug 30 11:08:08 CEST 2010


I like to have more control over the output format and data input by
separating these things.
How can I do this?

I would like to do something like this:
Logger.debug("some debug data", "Member", this.member, "Address",
this.address);

Then the formatter would output something like this:
Some debug data.
Member= [Member at dfsdf,  id=2434, ....]
Address= [Adress at dafa, street=bla, postalCode=34324234, ...]

The text between [] is the toString output.
I use this in other parts, like in my asserts and toString logging since a
few years now, and like it: development friendly, that is: easy usage in
code and readably output (especially with complex data structures this is a
requirement).

I could do the above through a static Utils method, something like this:
UtilsLogger.debug(logger, "some debug data", "Member", this.member,
"Address", this.address);
And then the Utils method will construct the complete log statement with the
{} in it.
But might it not an idea to make this part of the Logger Facade?.. Or is
there a way to extend SLF4j to add this myself?

Please some advice?
Ed





More information about the slf4j-user mailing list