<p>We got a couple spring boot applications in k8s that write both application log and tomcat access log to stdout.</p>
<p>When the log throughput is really high (either caused by amount of requests or amount of applciation logs) then it sometimes happens that log lines get interrupted.</p>
<p>In our case this looks like this:</p>
<pre><code>[04/Aug/2021:13:39:27 +0200] - &quot;GET /some/api/path?listWithIds=22838de1,e38e2021-08-04 13:39:26.774 ERROR 8 --- [ SomeThread-1] a.b.c.foo.bar.FooBarClass      : Oh no, some error occured
e7fb,cd089756,1b6248ee HTTP/1.1&quot; 200 (1 ms)
</code></pre>
<p>desired state:</p>
<pre><code>[04/Aug/2021:13:39:27 +0200] - &quot;GET /some/api/path?listWithIds=22838de1,e38ee7fb,cd089756,1b6248ee HTTP/1.1&quot; 200 (1 ms)
2021-08-04 13:39:26.774 ERROR 8 --- [ SomeThread-1] a.b.c.foo.bar.FooBarClass      : Oh no, some error occured
</code></pre>
<p>is there some way to prevent this?
maybe a tomcat, java or spring-boot setting?
or a setting on a container level to make sure that each line is buffered correctly</p>

FloxD
<p><code>System.out</code> had better be thread-safe, but that doesn't mean it won't interleave text when multiple threads write to it. Writing both application logs and HTTP server logs to the same stream seems like a mistake to me for at least this reason, but others as well.</p>
<p>If you want to aggregate logs together, using a character stream is <em>not</em> the way to do it. Instead, you need to use a logging framework that understands separate log-events which it can write coherently to that aggregate destination.</p>
<p>You may need to write your own <code>AccessLogValve</code>subclass which uses your logging framework instead of writing directly to a stream.</p>
