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" });

_______________________________________________
dev mailing list
[email protected]
http://slf4j.org/mailman/listinfo/dev

Reply via email to