[slf4j-dev] SLF4J enhancement (Object[])

Cédrik LIME clime at improve.fr
Sat Dec 17 22:37:58 CET 2005


All,

While new on this mailing list, I took the time to browse the history and can 
only say: pfew! :-)

I was initially going to plead for a trace and fatal level, but since there's 
been a lot of debates on the subject, I'll simply drop my "+1"... (no time to 
construct a full case point; it's been done already anyway: migrate from JCL, 
add a verboseness level for dev, yada yada yada.)


On to the real subject of this email: logging messages with more than 2 
arguments.

Logging complex statements is currently impossible with SLF4J API. Adding a
    Logger#debug(String format, Object[] args)
would solve all problems related to the number of arguments.
This is the same approach as for a backward compatibility for Java 5's varargs, 
as mentionned in an earlier post.

<http://www.slf4j.org/pipermail/dev/2005-June/000120.html> details how it could 
work (around middle of message):
logger.debug("User {} with email {} has id {}.",
        new Object[] { user.getName(), user.getEmail{}, user.getId()});

In <http://www.slf4j.org/pipermail/dev/2005-August/000242.html>, Ceki says:
"The Object[] param form has been requested very frequently. It's quite a 
reasonable request. As such, you can expect method accepting Object[] as 
parameter to be added in the near future."

As I understand, this method is simply not there because the code hasn't been 
written yet <http://www.slf4j.org/pipermail/dev/2005-July/000192.html> ("The 
method (cg5) is missing because there is no parsing code to back it up. I think 
that such code will eventually be added for the sake of completeness.").

Can we expect to see an implementation before 1.0, or is it too late a call?
I'll try to give it a shoot and see what code I can come up with. (Something 
along the lines: if the message contains only 1 "{}" then call toString on the 
argument, otherwise treat the arg as Object[].)

Now, I will leave the debat open to weither we need a new Object[] signature or 
not (simply use the 'Object' one). If you're on the Human Interface side, you'll 
vote for the addition of the Object[] method. If you're in the Pragmatic 
Interface camp, you'll want to keep the API as is... :-)

Finally, I'd like to take this oportunity to also propose "for the sake of 
completeness" a
    Logger#debug(String format, Object[] args, Throwable t)
What do you think?

Thanks for reading it all!

  Cédrik



More information about the slf4j-dev mailing list