Skip to content

Commit 252d865

Browse files
authored
fix: fixes really big logs being split in Docker that exceeded 16KB (#3946)
1 parent 02c28fd commit 252d865

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

assets/components/LogViewer/ComplexLogItem.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
<LogItem :logEntry @click="containers.length > 0 && showDrawer(LogDetails, { entry: logEntry })" class="clickable">
33
<ul class="space-x-4" @click="preventDefaultOnLinks">
44
<li v-for="(value, name) in validValues" :key="name" class="inline-flex">
5-
<span class="text-light">{{ name }}=</span><span class="font-bold" v-if="value === null">&lt;null&gt;</span>
5+
<span class="text-light">{{ name }}=</span>
6+
<span class="font-bold" v-if="value === null">&lt;null&gt;</span>
67
<template v-else-if="Array.isArray(value)">
7-
<span class="font-bold" v-html="JSON.stringify(value)"> </span>
8+
<span class="font-bold" v-html="JSON.stringify(value)"></span>
89
</template>
910
<span class="font-bold" v-html="stripAnsi(value.toString())" v-else></span>
1011
</li>

internal/docker/log_reader.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"encoding/binary"
77
"errors"
88
"io"
9+
"strings"
910
"sync"
1011

1112
"github.com/amir20/dozzle/internal/container"
@@ -52,8 +53,16 @@ func (d *LogReader) Read() (string, container.StdType, error) {
5253
std = container.STDERR
5354
}
5455

55-
return message, std, nil
56+
for !strings.HasSuffix(message, "\n") {
57+
tail, _, err := d.readEvent()
58+
if err != nil {
59+
return "", std, err
60+
}
5661

62+
message += tail[32:]
63+
}
64+
65+
return message, std, nil
5766
}
5867

5968
func (d *LogReader) readEvent() (string, StdType, error) {

internal/web/__snapshots__/web.snapshot

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,13 @@ Content-Type: text/html
8484
{"m":"INFO Testing stdout logs...","rm":"INFO Testing stdout logs...","ts":1589396137772,"id":466600245,"l":"info","s":"stdout","c":"123456"}
8585
{"m":"INFO Testing stderr logs...","rm":"INFO Testing stderr logs...","ts":1589396197772,"id":1101501603,"l":"info","s":"stderr","c":"123456"}
8686

87-
8887
/* snapshot: Test_handler_between_dates_with_everything_complex */
8988
{"m":{"msg":"a complex log message"},"rm":"{\"msg\":\"a complex log message\"}","ts":1589396197772,"id":62280847,"l":"unknown","s":"stdout","c":"123456"}
9089

91-
9290
/* snapshot: Test_handler_between_dates_with_fill */
9391
{"m":"INFO Testing stdout logs...","rm":"INFO Testing stdout logs...","ts":1589396137772,"id":466600245,"l":"info","s":"stdout","c":"123456"}
9492
{"m":"INFO Testing stderr logs...","rm":"INFO Testing stderr logs...","ts":1589396197772,"id":1101501603,"l":"info","s":"stderr","c":"123456"}
9593

96-
9794
/* snapshot: Test_handler_download_logs */
9895
INFO Testing logs...
9996

@@ -167,12 +164,15 @@ stdout or stderr is required
167164
/* snapshot: Test_handler_streamLogs_happy */
168165
:ping
169166

170-
data: {"m":"INFO Testing logs...","ts":0,"id":4256192898,"l":"info","s":"stdout","c":"123456"}
167+
data: {"m":"INFO Testing logs...\n","ts":0,"id":3835490584,"l":"info","s":"stdout","c":"123456"}
171168

172169

173170
event: container-event
174171
data: {"name":"container-stopped","host":"localhost","actorId":"123456","time":"<removed>"}
175172

173+
174+
175+
176176
/* snapshot: Test_handler_streamLogs_happy_container_stopped */
177177
:ping
178178

@@ -182,7 +182,7 @@ data: {"name":"container-stopped","host":"localhost","actorId":"123456","time":"
182182
/* snapshot: Test_handler_streamLogs_happy_with_id */
183183
:ping
184184

185-
data: {"m":"INFO Testing logs...","rm":"INFO Testing logs...","ts":1589396137772,"id":1469707724,"l":"info","s":"stdout","c":"123456"}
185+
data: {"m":"INFO Testing logs...","rm":"INFO Testing logs...","ts":1589396137772,"id":2908612274,"l":"info","s":"stdout","c":"123456"}
186186
id: 1589396137772
187187

188188

internal/web/logs_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func Test_handler_streamLogs_happy(t *testing.T) {
3636

3737
mockedClient := new(MockedClient)
3838

39-
data := makeMessage("INFO Testing logs...", container.STDOUT)
39+
data := makeMessage("INFO Testing logs...\n", container.STDOUT)
4040

4141
now := time.Now()
4242

@@ -80,7 +80,7 @@ func Test_handler_streamLogs_happy_with_id(t *testing.T) {
8080

8181
mockedClient := new(MockedClient)
8282

83-
data := makeMessage("2020-05-13T18:55:37.772853839Z INFO Testing logs...", container.STDOUT)
83+
data := makeMessage("2020-05-13T18:55:37.772853839Z INFO Testing logs...\n", container.STDOUT)
8484

8585
started := time.Date(2020, time.May, 13, 18, 55, 37, 772853839, time.UTC)
8686

0 commit comments

Comments
 (0)