diff --git a/pkg/logging/interface.go b/pkg/logging/interface.go index ebbabb44f..89f8061fe 100644 --- a/pkg/logging/interface.go +++ b/pkg/logging/interface.go @@ -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...) +} diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 150280141..e2c802581 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -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. @@ -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]