Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix logrus usage #143

Merged
merged 1 commit into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/logging/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ func NewBufferedContext() (logging.Context, *bytes.Buffer) {
var buf bytes.Buffer
return logging.New(buflogr.NewWithBuffer(&buf)), &buf
}

var liblogcontext = logging.NewWithBase(logging.DefaultContext())

// DefaultContext is the local log context used all over the ocm library.
func DefaultContext() logging.Context {
return liblogcontext
}

// Logger provides a logger for the logging context of the ocm library.
func Logger(mctx ...logging.MessageContext) logging.Logger {
return liblogcontext.Logger(mctx...)
}
4 changes: 3 additions & 1 deletion pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import (
"github.com/mandelsoft/vfs/pkg/vfs"
"github.com/spf13/cobra"
"sigs.k8s.io/yaml"

ocmlog "github.com/open-component-model/ocm/pkg/logging"
)

// PrintPrettyYaml prints the given objects as yaml if enabled.
Expand Down Expand Up @@ -122,7 +124,7 @@ func RandomString(n int) string {
value = int(v.Int64())
} else {
// insecure fallback to provide a valid result
logrus.Warnf("failed to generate random number: %s", err)
ocmlog.Logger().Error("failed to generate random number", "error", err)
value = rand.Intn(len(chars)) //nolint: gosec // only used as fallback
}
b[i] = chars[value]
Expand Down