marker is not an rvalue in logback

270 views Asked by At

I have this filter in my logback-spring.xml:

<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
    <evaluator>
        <expression>
            return marker instanceof com.package.logging.Metrics.Marker;
        </expression>
    </evaluator>
    <onMatch>DENY</onMatch>
    <onMismatch>NEUTRAL</onMismatch>
</filter>

the filter has been working until I started upgrading my dependencies. Here's a list of the most relevant upgrades:

  • Java 8 -> 17

  • Spring boot 2.5 -> 3.0.8

  • ch.qos.logback:logback-core:1.2.11 -> 1.4.11

  • ch.qos.logback:logback-classic:1.2.11 -> 1.4.11

  • org.codehaus.janino:janino:3.1.7 -> 3.1.10

Now it's giving me this error on application startup:

ERROR in ch.qos.logback.classic.boolex.JaninoEventEvaluator@40d10481 - Could not start evaluator with expression [return marker instanceof com.package.logging.Metrics.Marker;] org.codehaus.commons.compiler.CompileException: Line 2, Column 8: Expression "marker" is not an rvalue

1

There are 1 answers

0
Spring On

Issue arises due to the deprecated getMarker() Method:

https://logback.qos.ch/apidocs/ch/qos/logback/classic/spi/ILoggingEvent.html

This is how I solved in my case:

old expression:

  <expression>return marker != null &amp;&amp; marker.getName().equals("FUNC");</expression>

changed to:

  <expression>return event.getMarkerList() != null &amp;&amp; !event.getMarkerList().isEmpty() &amp;&amp; ((org.slf4j.Marker) event.getMarkerList().get(0)).getName().equals("FUNC");</expression>