Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 893
ilooner Avatar asked Jan 23 '26 07:01

ilooner


1 Answers

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.

like image 126
wilx Avatar answered Jan 24 '26 21:01

wilx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!