logback-access-spring-boot-starter icon indicating copy to clipboard operation
logback-access-spring-boot-starter copied to clipboard

Exclude health check probes from access logs

Open fiunchinho opened this issue 6 years ago • 4 comments

Hi! It's common to have a load balancer or container orchestration system probing that your application is ready to serve traffic. At the moment, I'm using Janino to exclude those access logs from appearing, but I believe it's such a common issue that it would be helpful to provide a Spring property to enable/disable excluding the health check access logs. The request uri to be excluded would be the actuator health endpoint, and only when the response is 200 OK. That way, if something goes wrong, you still see the errors. But you no longer get an infinite log full of GET /health 200 OK.

I'd be happy to contribute, but I don't know how that can be done in this library.

fiunchinho avatar Aug 06 '18 17:08 fiunchinho

Hello!

Logback access filters are designed to solve this problem. Can you more clearly explain your use case with janino? I'm a little puzzled, because logback also uses janino for filters:

<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
    <evaluator name="EvalActuator">
        <expression>
         !((event.getStatusCode() == 200) &amp;&amp; (event.getRequestURI().startsWith("/actuator"))
        </expression>
    </evaluator>
    <onMismatch>DENY</onMismatch>
</filter>

a8t3r avatar Dec 03 '18 18:12 a8t3r

actuators context is customizable... I think it would be much better to use a custom spring boot property, something like spring.logging.access.exclude-url-patterns

nightswimmings avatar Jan 25 '19 13:01 nightswimmings

Another way to configure the EvaluatorFilter:

<filter class="ch.qos.logback.core.filter.EvaluatorFilter">
    <evaluator class="ch.qos.logback.access.net.URLEvaluator">
        <URL>/health</URL>
        <!-- add more URLs as needed -->
    </evaluator>
    <OnMismatch>NEUTRAL</OnMismatch>
    <OnMatch>DENY</OnMatch>
</filter>

adammichalik avatar Jul 21 '20 09:07 adammichalik

Hi @fiunchinho I would like to know how you enabled actuator health logs to be printed with status?

saranyajithin avatar Jan 09 '23 18:01 saranyajithin