Skip to content

Commit

Permalink
chore: make GetDebugLevel reusable
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterSchafer committed Aug 1, 2024
1 parent f2949a9 commit ebea548
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
16 changes: 3 additions & 13 deletions cliv2/cmd/cliv2/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,9 @@ import (

"github.com/snyk/go-application-framework/pkg/configuration"
"github.com/snyk/go-application-framework/pkg/logging"
)

func getDebugLevel(config configuration.Configuration) zerolog.Level {
loglevel := zerolog.DebugLevel
if loglevelString := config.GetString("snyk_log_level"); loglevelString != "" {
var err error
loglevel, err = zerolog.ParseLevel(loglevelString)
if err != nil {
loglevel = zerolog.DebugLevel
}
}
return loglevel
}
debug_tools "github.com/snyk/cli/cliv2/internal/debug"
)

func initDebugLogger(config configuration.Configuration) *zerolog.Logger {
debug := config.GetBool(configuration.DEBUG)
Expand Down Expand Up @@ -52,7 +42,7 @@ func initDebugLogger(config configuration.Configuration) *zerolog.Logger {

scrubLogger := logging.NewScrubbingWriter(zerolog.MultiLevelWriter(consoleWriter), logging.GetScrubDictFromConfig(config))
localLogger := zerolog.New(scrubLogger).With().Str("ext", "main").Str("separator", "-").Timestamp().Logger()
loglevel := getDebugLevel(config)
loglevel := debug_tools.GetDebugLevel(config)
localLogger.Log().Msgf("Using log level: %s", loglevel)

debugLogger := localLogger.Level(loglevel)
Expand Down
18 changes: 18 additions & 0 deletions cliv2/internal/debug/debug.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package debug

import (
"github.com/rs/zerolog"
"github.com/snyk/go-application-framework/pkg/configuration"
)

func GetDebugLevel(config configuration.Configuration) zerolog.Level {
loglevel := zerolog.DebugLevel
if loglevelString := config.GetString("snyk_log_level"); loglevelString != "" {
var err error
loglevel, err = zerolog.ParseLevel(loglevelString)
if err != nil {
loglevel = zerolog.DebugLevel
}
}
return loglevel
}

0 comments on commit ebea548

Please sign in to comment.