As we reevaluate how to best support and maintain Staging Ref in the future, we encourage development teams using this environment to highlight their use cases in the following issue: https://gitlab.com/gitlab-com/gl-infra/software-delivery/framework/software-delivery-framework-issue-tracker/-/issues/36.

Skip to content
Snippets Groups Projects
Commit 384cc476 authored by Nick Thomas's avatar Nick Thomas
Browse files

Default to info level for an empty log-level

I'd assumed that the `omitempty` directive for LogLevel in
internal/config/config.go would get us this behaviour. If it did, we
wouldn't have had to specify the default twice. Unfortunately, it
doesn't, which is to say that given a config file like:

```
log_level:
```

The default *is* overridden by the empty string.

It's an easy enough fix.

Changelog: fixed
parent ede95ae7
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -22,6 +22,14 @@ func logFmt(inFmt string) string {
return inFmt
}
func logLevel(inLevel string) string {
if inLevel == "" {
return "info"
}
return inLevel
}
func logFile(inFile string) string {
if inFile == "" {
return "stderr"
Loading
Loading
@@ -35,7 +43,7 @@ func buildOpts(cfg *config.Config) []log.LoggerOption {
log.WithFormatter(logFmt(cfg.LogFormat)),
log.WithOutputName(logFile(cfg.LogFile)),
log.WithTimezone(time.UTC),
log.WithLogLevel(cfg.LogLevel),
log.WithLogLevel(logLevel(cfg.LogLevel)),
}
}
Loading
Loading
Loading
Loading
@@ -30,9 +30,11 @@ func TestConfigure(t *testing.T) {
tmpFile.Close()
data, err := os.ReadFile(tmpFile.Name())
dataStr := string(data)
require.NoError(t, err)
require.Contains(t, string(data), `msg":"this is a test"`)
require.NotContains(t, string(data), `msg:":"debug log message"`)
require.Contains(t, dataStr, `"msg":"this is a test"`)
require.NotContains(t, dataStr, `"msg":"debug log message"`)
require.NotContains(t, dataStr, `"msg":"unknown log level`)
}
func TestConfigureWithDebugLogLevel(t *testing.T) {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment