Hi,

I'm upgrading an application from Log4j v1 to v2.

The v1 code often uses the debug()/info()/etc. methods with the
`Logger.debug(Object message, Throwable throwable)` signature to throw
errors while logging.  In many cases, the `message` String is composed
using concatenation, as with

    logger.debug("Compiler Exception for " + datafilter, e);

where `datafilter` is a String and `e` is an Exception (`logger`, of
course, is a Logger).

I'm looking for the simplest drop-in replacement for such lines to migrate
them to Log4j v2 and its requirement for parameterized messages.  The Log4j
migration guide provides a drop-in replacement for the simplest case; i.e.

    logger.info("hi " + userName) -> logger.info("hi {}", userName)

but when I apply this naively to my case,

    /* Log4j v2 ? */
    logger.debug("Compiler Exception for " + datafilter, e) ->
logger.debug("Compiler Exception for {}", datafilter, e)

the method signature looks odd and I'm not sure it will work.  I can't test
it because the code is not functional because it's in the middle of Log4j
remediation.

My question is, is the above example labeled 'Log4j v2 ?' correct for
migrating from Log4j v1 to v2?  If not, what's the simplest drop-in
replacement for the original `debug()` method call that includes a
Throwable as an argument?

Thanks,
Joel

Reply via email to