[slf4j-dev] Logger.debug(String, Object[])?

Ceki Gülcü listid at qos.ch
Fri Aug 5 11:29:40 CEST 2005


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.


At 08:20 AM 8/4/2005, Curt Arnold wrote:
>Been reading the varargs stuff in JDK 1.5 and it seems like it might
>be desirable to add methods that take an Object[] parameter in
>addition to the existing Logger.debug(String, Object) methods.  For
>example:
>
>interface Logger {
>void debug(String format, Object param1); //existing method
>void debug(String format, Object[] params);
>}
>
>The second form would be like a
>
>void debug(String format, Object... params)
>
>Obviously there would be a construction cost in constructing the
>array unless you happened to happened to have it around.  However, if
>you were willing to take the hit, it would open up all sorts of
>combinations of parameters.
>
>The implementation  would be something like:
>
>void debug(String format, Object param1) {
>    if (isDebugEnabled()) {
>        String msg = MessageFormat.format(new Object[] { param1 });
>        logger.finer(msg);
>    }
>}
>
>void debug(String format, Object[] params) {
>    if (isDebugEnabled()) {
>        String msg = MessageFormat.format(params);
>        logger.finer(msg);
>    }
>}
>
>This way, you could do:
>
>logger.debug("This first five letters of the latin alphabet are {},
>{}, {}, {}, {}.", new Object[] {"A", "B", "C", "D", "E" });

-- 
Ceki Gülcü

   The complete log4j manual: http://www.qos.ch/log4j/





More information about the slf4j-dev mailing list