logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject Re: Checking if logger is enabled for a specific marker
Date Tue, 23 Jun 2015 08:23:14 GMT

As our unit tests show, markers work, unless you've found a bug!

Can you create a unit test with configuration file that demonstrate your

Which version of Log4j are you using?

Note that we have a lot of unit tests for you to use as inspiration and
debugging help.


On Mon, Jun 22, 2015 at 5:22 AM, David KOCH <dkoch@ezakus.com> 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

E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message