Skip to content

Commit

Permalink
initialize: add standalone initialization functions
Browse files Browse the repository at this point in the history
Signed-off-by: Hank Donnay <hdonnay@redhat.com>
  • Loading branch information
hdonnay committed Mar 10, 2021
1 parent e7bf3b1 commit 2d27ae5
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 188 deletions.
13 changes: 13 additions & 0 deletions initialize/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

"github.com/quay/clair/v4/config"
)

// Logging will set the global logging level for Clair,
Expand All @@ -26,6 +28,7 @@ func (i *Init) Logging() error {
return nil
}

// LogLevel does a string-to-level mapping.
func LogLevel(level string) zerolog.Level {
level = strings.ToLower(level)
switch level {
Expand All @@ -49,3 +52,13 @@ func LogLevel(level string) zerolog.Level {
return zerolog.InfoLevel
}
}

// Logging configures a logger according to the provided configuration and returns
// a configured Context.
func Logging(ctx context.Context, cfg *config.Config) (context.Context, error) {
zerolog.SetGlobalLevel(LogLevel(cfg.LogLevel))
l := log.With().Timestamp().Logger()
ctx = l.WithContext(ctx)
l.Debug().Str("component", "initialize/Logging").Msg("logging initialized")
return ctx, nil
}

0 comments on commit 2d27ae5

Please sign in to comment.