Skip to content

Commit

Permalink
Setting a logger without its level
Browse files Browse the repository at this point in the history
This may not have an real use-case, but Firecracker supports
the combination.

Signed-off-by: Kazuyoshi Kato <[email protected]>
  • Loading branch information
kzys committed Sep 2, 2020
1 parent ee1e7c4 commit 758a422
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,9 +616,16 @@ func (m *Machine) setupLogging(ctx context.Context) error {
return nil
}

// m.Cfg.LogLevel cannot be nil, but Firecracker allows setting a logger
// without its level. Converting "" to nil to support the corner case.
level := String(m.Cfg.LogLevel)
if StringValue(level) == "" {
level = nil
}

l := models.Logger{
LogPath: String(path),
Level: String(m.Cfg.LogLevel),
Level: level,
ShowLevel: Bool(true),
ShowLogOrigin: Bool(false),
}
Expand Down
11 changes: 9 additions & 2 deletions machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ func TestLogAndMetrics(t *testing.T) {
logLevel string
quiet bool
}{
{logLevel: "", quiet: false},
{logLevel: "Info", quiet: false},
{logLevel: "Error", quiet: true},
}
Expand All @@ -432,9 +433,15 @@ func TestLogAndMetrics(t *testing.T) {
out := testLogAndMetrics(t, test.logLevel)
if test.quiet {
assert.Regexp(t, `^Running Firecracker v0\.\d+\.0`, out)
} else {
assert.Contains(t, string(out), ":"+strings.ToUpper(test.logLevel)+"]")
return
}

// By default, Firecracker's log level is Warn.
logLevel := "WARN"
if test.logLevel != "" {
logLevel = strings.ToUpper(test.logLevel)
}
assert.Contains(t, out, ":"+logLevel+"]")
})
}
}
Expand Down

0 comments on commit 758a422

Please sign in to comment.