Cherry
Cherry

Reputation: 33608

Does apache commons logging support placeholders?

Here is a user guide about apache commons logging, but it has no examples about placeholders. Slf4j can replace {} according to log level, e.g. it does not call toString and does not replace {} when log level is not enabled. Does apache commons logging supports this functionality?

Upvotes: 11

Views: 2401

Answers (1)

knittl
knittl

Reputation: 265707

No, it (i.e. Apache commons logging) does not support placeholders. If you need to dynamically produce a string (an expensive operation due to memory allocations), wrap the logging invocation in a condition:

Performance is often a logging concern. By examining the appropriate property, a component can avoid expensive operations (producing information to be logged).

For example,

if (log.isDebugEnabled()) {
    ... do something expensive ...
    log.debug(theResult);
}

— [https://commons.apache.org/proper/commons-logging/apidocs/org/apache/commons/logging/Log.html]

Upvotes: 0

Related Questions