[logback-user] Logback-access pollutes logs with binary file content

Gediminas Rimša gediminas.rimsa at gmail.com
Mon Sep 21 12:04:57 CEST 2020


Hello.

We have a Spring boot app exposing a RESTful API that runs on embedded
Tomcat (latest versions) and uses logback-access (also latest 1.2.3).

Recently I noticed that access logs include raw binary content of
images/PDF files.

Example from logs:

> POST /projects/projectId/images HTTP/1.1 | status code: 200 | elapsed
time: 664 | request: GIF89a� d �[[ most content ommitted ]]g��� w���� ; |
response: {"id":"877f2338-293d-403b-99fb-09fc631ce7b3"}
> GET /projects/projectid/images/877f2338-293d-403b-99fb-09fc631ce7b3
HTTP/1.1 | status code: 200 | elapsed time: 538 | request:  | response:
[IMAGE CONTENTS SUPPRESSED]

What's the best way to configure suppression of request and response bodies
(preferably based on content type)?

Looking at the code, image content suppression happens in
`ch.qos.logback.access.spi.AccessEvent#getResponseContent`, but it only
checks if content type starts with `image/`. I also do not see any code for
binary content suppression in
`ch.qos.logback.access.spi.AccessEvent#getRequestContent`.

I traced response image content suppression was added with this commit:
https://github.com/qos-ch/logback/commit/69290e182f8db6589eadd5a3c485a37255384893
(all the way back in 2007).

Our config:

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <filter class="ch.qos.logback.core.filter.EvaluatorFilter">
            <evaluator class="ch.qos.logback.access.net.URLEvaluator">
                <URL>/ping</URL>
            </evaluator>
            <OnMismatch>NEUTRAL</OnMismatch>
            <OnMatch>DENY</OnMatch>
        </filter>
        <encoder>
            <pattern>%requestURL | status code: %statusCode | elapsed
time: %elapsedTime | request: %magenta(%requestContent) | response:
%cyan(%responseContent)</pattern>
        </encoder>
    </appender>
    <appender-ref ref="STDOUT"/>
</configuration>


Thanks,
Gediminas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20200921/0fac2b79/attachment.html>


More information about the logback-user mailing list