I've managed to integrate logback-access.xml with a Spring Boot on Tomcat project but for the life of me I cannot get it to respect my ch.qos.logback.core.filter.EvaluatorFilter. It definitely sees and uses my logback-access.xml file (if I change the encoder.pattern the output messages change), but seems oblivious of the filter I configure there; I don't get the effect I am looking for which is suppression of any access log messages from the /healthz URL and I don't see my System.out.println cry for help
The logback-access.xml file looks like
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
<evaluator>
<expression>
System.out.println("ROBERT!!!! " + formattedMessage);
return formattedMessage.contains("/healthz");
</expression>
</evaluator>
<OnMismatch>NEUTRAL</OnMismatch>
<OnMatch>DENY</OnMatch>
</filter>
<encoder>
<pattern>%h %l %u %user %date "%r" %s %b</pattern>
</encoder>
</appender>
<appender-ref ref="CONSOLE"/>
</configuration>
The build.gradle has the requisite dependencies
compile(group: 'net.rakugakibox.springbootext', name: 'spring-boot-ext-logback-access', version: '1.6')
compile group: 'org.codehaus.janino', name: 'janino', version: '3.0.7'
The logging output mocks me...
0:0:0:0:0:0:0:1 - - - 22/Jun/2017:15:16:17 -0700 "GET /healthz HTTP/1.1" 200 27
0:0:0:0:0:0:0:1 - - - 22/Jun/2017:15:18:18 -0700 "GET /v1/scouting_activities/fcdc7aae-4f11-4476-bb81-6d5e3f52e1b4 HTTP/1.1" 200 1939
How do I get an ch.qos.logback.core.filter.EvaluatorFilter in logback-access.xml under Spring Boot 1.4.1 to work and skip the GET /healthz requests?
If you debug the logback configuration you will see the problem(<configuration debug="true">
).
11:03:53,559 |-ERROR in ch.qos.logback.access.boolex.JaninoEventEvaluator@649725e3 - Could not start evaluator with expression [System.out.println("ROBERT!!!! " + formattedMessage);
return false;] org.codehaus.commons.compiler.CompileException: Line 1, Column 52: Expression "formattedMessage" is not an rvalue
at org.codehaus.commons.compiler.CompileException: Line 1, Column 52: Expression "formattedMessage" is not an rvalue
The problem is that logback-access does not operate on ILoggingEvent
, rather it operates on IAccessEvent
.
There are JaninoEventEvaluator
classes for each type of event.
The logback-access evaluator does not have the formattedMessage
value.
It does however have the event
value which is an instance of a IAccessEvent
.
So just change your expression to the below and it should work.
<expression>
System.out.println("ROBERT!!!! " + event.getRequestURI());
return event.getRequestURI().contains("/healthz");
</expression>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With