Substituting parameters in a log message and adding Throwable to Log4j 2

I am trying to log an exception and would like to include a different variable value in the log message. Is there a Logger API that does this?

logger.error("Logging in user {} with birthday {}", user.getName(), user.getBirthdayCalendar(), exception);
+4
source share
1 answer

Have you tried watching ParameterizedMessage ?

From the documents

Parameters:

messagePattern - the message format string. This will be a String containing "{}" placeholders where the parameters must be substituted.

objectArgs - arguments to substitute.

throwable - A Throwable

+6
source

Source: https://habr.com/ru/post/1626612/


All Articles