Log4j2: log level INFO but special markers with DEBUG

Viewed 12

Hi I want to filter my logs in a special way: I have a high frequented system. A lot of devices are connected and are sending messages all time. To log all is impossible. Now I'm searching for a way to log all things are not depending on device messages and to log the other messages only of a special device. I found, that I could mark these logs but I have no idea to combine both log types:

public someMethod (String serial){
   Marker sm = org.slf4j.MarkerFactory.getMarker(serial);
   log.info("A log message I want to find each time");
   log.debug(sm, "This log I want to filter out only for serial: "+ serial);
   ...

I'm working with spring boot and log4j. I tried vaious filters, but without success. Any one any idea?

1 Answers

I found it by myself: here the start of my log4j2.xml:

<Configuration monitorInterval="60">
   <filters>
      <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="NEUTRAL"/>
      <MarkerFilter marker="serial" onMatch="ACCEPT" onMismatch="DENY"/>
   </filters>
   ...
 <Appenders> ...
Related