Skip to content

Commit

Permalink
mute application logs (#6407)
Browse files Browse the repository at this point in the history
  • Loading branch information
tejal29 authored Aug 11, 2021
1 parent 2664f56 commit 73d1ec9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/skaffold/kubernetes/logger/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func newKubernetesLogFormatter(config Config, colorPicker output.ColorPicker, is
func (k *kubernetesLogFormatter) Name() string { return k.prefix }

func (k *kubernetesLogFormatter) PrintLine(out io.Writer, line string) {
if k.isMuted() {
return
}
formattedPrefix := k.prefix
if output.IsColorable(out) {
formattedPrefix = k.color().Sprintf("%s", k.prefix)
Expand All @@ -72,11 +75,9 @@ func (k *kubernetesLogFormatter) PrintLine(out io.Writer, line string) {
formattedLine := fmt.Sprintf("%s%s", formattedPrefix, line)
eventV2.ApplicationLog(k.pod.Name, k.container.Name, formattedPrefix, line, formattedLine)

if !k.isMuted() {
k.lock.Lock()
defer k.lock.Unlock()
fmt.Fprint(out, formattedLine)
}
k.lock.Lock()
defer k.lock.Unlock()
fmt.Fprint(out, formattedLine)
}

func (k *kubernetesLogFormatter) color() output.Color {
Expand Down
29 changes: 29 additions & 0 deletions pkg/skaffold/kubernetes/logger/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,32 @@ func TestPrefix(t *testing.T) {
})
}
}

func TestPrintline(t *testing.T) {
tests := []struct {
description string
isMuted bool
expected string
}{
{
description: "muted",
isMuted: true,
},
{
description: "unmuted",
expected: "[hello container]test line",
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
pod := podWithName("hello")
f := newKubernetesLogFormatter(&mockConfig{log: latestV1.LogsConfig{
Prefix: "auto",
}}, &mockColorPicker{}, func() bool { return test.isMuted }, &pod,
containerWithName("container"))
var out bytes.Buffer
f.PrintLine(&out, "test line")
t.CheckDeepEqual(test.expected, out.String())
})
}
}

0 comments on commit 73d1ec9

Please sign in to comment.