sorry, hit "send" too soon, continued: However, the condition only ever evaluates to to false if the logger itself is de-activated. log4j2 version is 2.1.
Thank you, /David On 23 June 2015 at 17:15, David KOCH <[email protected]> wrote: > Hello, > > Thank you for your replies. Don't get me wrong. The markers and marker > filters themselves work. However, my point was that the method > Logger#isEnabled(Level level, Marker marker) only checks if the logger is > enabled for the level and not the marker. > > Minimal example: > > package com.ezakus.log; > > import org.apache.logging.log4j.LogManager; > import org.apache.logging.log4j.Logger; > import org.apache.logging.log4j.Marker; > import org.apache.logging.log4j.MarkerManager; > > > public class LoggerWithMarkerTest { > > private static Logger logger = > LogManager.getLogger(LoggerWithMarkerTest.class.getName()); > private static final Marker markerOne = > MarkerManager.getMarker("marker_one"); > > public static void main(String[] args) { > if (logger.isInfoEnabled(markerOne)) { > System.out.println("Activated!"); > logger.info(markerOne, "We are logging!"); > } > } > > } > > with configuration: > > <?xml version="1.0" encoding="UTF-8"?> > <Configuration status="DEBUG" monitorInterval="10"> > > <Appenders> > <Console name="Console" target="SYSTEM_OUT"> > <!-- <MarkerFilter marker="marker_one" onMatch="DENY" > onMismatch="NEUTRAL"/> --> > <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - > %marker - %msg%n"/> > </Console> > </Appenders> > > <Loggers> > <Root level="info"> > <AppenderRef ref="Console"/> > </Root> > > <Logger name="com.ezakus.log.LoggerWithMarkerTest" level="info" > additivity="false"> > <MarkerFilter marker="marker_one" onMatch="DENY" > onMismatch="NEUTRAL"/> > <AppenderRef ref="Console"/> > </Logger> > > </Loggers> > > </Configuration> > > > The behaviour I expect with that configuration is that the condition in > the code evaluates to false. However, it only ever evalu > > > > On 23 June 2015 at 15:42, Ralph Goers <[email protected]> wrote: > >> I’m surprised that case isn’t working for you. Looking at the code leads >> me to believe it should but I will have to test it myself to see what is >> going on. That could take a few days. >> >> Ralph >> >> > On Jun 22, 2015, at 5:22 AM, David KOCH <[email protected]> wrote: >> > >> > Hello, >> > >> > Is there any way to programatically determine if a logger is enabled >> for a >> > specific log level and marker? If so how? There is a >> Logger#isEnabled(Level >> > level, Marker marker) method but it seems it ignores the marker >> argument. >> > >> > I would like to avoid carrying out relatively expensive operations >> required >> > for preparing the log message when it's not required. The alternative, >> > implementing Message#getFormattedMessage would be quite clumsy in this >> case >> > so I'd like to be able to pre-check based on marker and log level >> instead. >> > >> > I did like this in the log4j.xml: >> > >> > <Logger name="com.xxxxx.rtb.log.LoggingBidInterceptor" level="info" >> > additivity="false"> >> > <MarkerFilter marker="bid_req_proto" onMatch="DENY" >> onMismatch="DENY"/> >> > <AppenderRef ref="Console"/> >> > <AppenderRef ref="KafkaBidRequest" level="info"/> >> > <AppenderRef ref="KafkaBidResponse" level="off"/> >> > </Logger> >> > >> > but logger.isInfoEnabled(MarkerManager.getMarker("bid_req_proto")) >> > evaluates to to "true" whatever way I set up the MarkerFilter. >> > >> > Regards, >> > >> > /David >> >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [email protected] >> For additional commands, e-mail: [email protected] >> >> >
