Skip to content

Commit 73d1ec9

Browse files
authored
mute application logs (#6407)
1 parent 2664f56 commit 73d1ec9

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

pkg/skaffold/kubernetes/logger/formatter.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ func newKubernetesLogFormatter(config Config, colorPicker output.ColorPicker, is
6060
func (k *kubernetesLogFormatter) Name() string { return k.prefix }
6161

6262
func (k *kubernetesLogFormatter) PrintLine(out io.Writer, line string) {
63+
if k.isMuted() {
64+
return
65+
}
6366
formattedPrefix := k.prefix
6467
if output.IsColorable(out) {
6568
formattedPrefix = k.color().Sprintf("%s", k.prefix)
@@ -72,11 +75,9 @@ func (k *kubernetesLogFormatter) PrintLine(out io.Writer, line string) {
7275
formattedLine := fmt.Sprintf("%s%s", formattedPrefix, line)
7376
eventV2.ApplicationLog(k.pod.Name, k.container.Name, formattedPrefix, line, formattedLine)
7477

75-
if !k.isMuted() {
76-
k.lock.Lock()
77-
defer k.lock.Unlock()
78-
fmt.Fprint(out, formattedLine)
79-
}
78+
k.lock.Lock()
79+
defer k.lock.Unlock()
80+
fmt.Fprint(out, formattedLine)
8081
}
8182

8283
func (k *kubernetesLogFormatter) color() output.Color {

pkg/skaffold/kubernetes/logger/formatter_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,32 @@ func TestPrefix(t *testing.T) {
222222
})
223223
}
224224
}
225+
226+
func TestPrintline(t *testing.T) {
227+
tests := []struct {
228+
description string
229+
isMuted bool
230+
expected string
231+
}{
232+
{
233+
description: "muted",
234+
isMuted: true,
235+
},
236+
{
237+
description: "unmuted",
238+
expected: "[hello container]test line",
239+
},
240+
}
241+
for _, test := range tests {
242+
testutil.Run(t, test.description, func(t *testutil.T) {
243+
pod := podWithName("hello")
244+
f := newKubernetesLogFormatter(&mockConfig{log: latestV1.LogsConfig{
245+
Prefix: "auto",
246+
}}, &mockColorPicker{}, func() bool { return test.isMuted }, &pod,
247+
containerWithName("container"))
248+
var out bytes.Buffer
249+
f.PrintLine(&out, "test line")
250+
t.CheckDeepEqual(test.expected, out.String())
251+
})
252+
}
253+
}

0 commit comments

Comments
 (0)