Take the 2-minute tour ×

Java 5 has introduced many features that can be make logging statements less cluttering, such as variable number of arguments and printf. That can alleviate all the message building code that happens when something is logged, as well as the surrounding if.

For example, instead of writing:

if (log.isDebugEnabled()
    log.debug("User id: "+uid+", Request id:"
    + rid +", Client IP: "+ip+" blah blah blah");

I would like to write:

log.debug("User id: %s, Request id: %s, Client IP: %s blah blah blah",
uid, rid, ip);

or something like that.

Do you know a logging framework or an extension to a logging framework that can help with that?

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

Log5j is exacly what you need.

share|improve this answer
add comment

Simple Logging Facade for Java (SLF4J)

The Simple Logging Facade for Java or (SLF4J) is intended to serve as a simple facade for various logging APIs allowing to the end-user to plug in the desired implementation at deployment time. SLF4J also supports a bridging legacy APIs as well as a source code migration tool.

SLF4J API offers an advanced abstraction of various logging systems, including JDK 1.4 logging, log4j and logback. Features include parameterized logging and MDC support.


logger.info("{} {}!", "Hello", "world");

produces "Hello world!" but only if info level is enabled.

share|improve this answer
SLF4J does not have a variable-argument log statement like the OP requests. (Only 1 and 2 arguments, the rest are Object[] –  krosenvold Feb 18 '09 at 11:24
Hmmm, true. I never realized that. (Bug for this problem is at: bugzilla.slf4j.org/show_bug.cgi?id=31) –  Peter Štibraný Feb 18 '09 at 12:20
add comment

It is easy enough to write your own wrapper methods for that.

share|improve this answer
add comment

Your Answer


