ilooner
ilooner

Reputation: 2560

How can you include a marker in a log message with SLF4J with Log4j

I am using markers in SLF4J with Log4j in the following way

final Marker marker = MarkerFactory.getMarker("boom");
logger.info(marker, "BLAH BLAH: {}", stuff);

How can I include the marker in the log message that is output. For example I would want the code above to output something like:

INFO - (boom): BLAH BLAH: something

Currently the marker is not displayed

INFO: BLAH BLAH: something

I have been trying to find a way to configure this in the log4j.properties but was unable to find anything about displaying markers.

Upvotes: 3

Views: 3920

Answers (1)

wilx
wilx

Reputation: 18268

This depends on the version of log4j that you are trying to use as the logging back-end. The classical Log4j 1.2.x does not support Markers but it seems to support MDC with SLF4J. Log4j 2.x does seem to support markers natively. You can use %marker in layout format specifier.

Upvotes: 5

Related Questions