简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM