diff --git a/go.mod b/go.mod index 533102b50..78117d234 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/google/uuid v1.6.0 github.com/opencontainers/selinux v1.15.1 github.com/prometheus/procfs v0.21.1 - github.com/sirupsen/logrus v1.10.0 + github.com/sirupsen/logrus v1.10.2 github.com/stretchr/testify v1.12.1 github.com/urfave/cli/v2 v2.27.7 golang.org/x/mod v0.41.0 diff --git a/go.sum b/go.sum index b22f09895..462e4f34f 100644 --- a/go.sum +++ b/go.sum @@ -82,8 +82,8 @@ github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0t github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/sirupsen/logrus v1.10.0 h1:T8MxJJXVZkfcC5zSRMRAg2F8+lxjmUCGGWPzFxO+Msc= -github.com/sirupsen/logrus v1.10.0/go.mod h1:FXZFonkDAnFozmO+5hGAFvB0Yg9/j2SIhA/QuIkP180= +github.com/sirupsen/logrus v1.10.2 h1:G2SED73/qrAu6YwbdxOD6peLkCBI3z7L+ykJFTXJBBo= +github.com/sirupsen/logrus v1.10.2/go.mod h1:SLEg8TqYulVKKfIGHldVp2K2aYz2DKSVBq4g/H5bR7Q= github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/vendor/github.com/sirupsen/logrus/CHANGELOG.md b/vendor/github.com/sirupsen/logrus/CHANGELOG.md index 650f64988..683cec908 100644 --- a/vendor/github.com/sirupsen/logrus/CHANGELOG.md +++ b/vendor/github.com/sirupsen/logrus/CHANGELOG.md @@ -2,6 +2,21 @@ All notable changes to this project will be documented in this file. +## 1.10.2 + +Changed: + + * Update `github.com/stretchr/testify` to v1.12.1, removing the legacy + `gopkg.in/yaml.v3` dependency. + +## 1.10.1 + +Fixes: + + * Fix a regression introduced in v1.10.0 where `TextFormatter` could panic + when formatting nil or panicking `error` and `fmt.Stringer` values. + * Allow function-backed implementations of `error` as field values. + ## 1.10.0 Fixes: diff --git a/vendor/github.com/sirupsen/logrus/entry.go b/vendor/github.com/sirupsen/logrus/entry.go index 1cb4b5204..82de41f9f 100644 --- a/vendor/github.com/sirupsen/logrus/entry.go +++ b/vendor/github.com/sirupsen/logrus/entry.go @@ -159,15 +159,7 @@ func (entry *Entry) String() (string, error) { // WithError adds an error as single field (using the key defined in [ErrorKey]) // to the Entry. func (entry *Entry) WithError(err error) *Entry { - // Avoid reflection work in WithFields; we know the type is an error; - // copy the entry data and set the ErrorKey directly. - dup := entry.dup() - dup.Data = maps.Clone(entry.Data) - if dup.Data == nil { - dup.Data = make(Fields, 1) - } - dup.Data[ErrorKey] = err - return dup + return entry.WithField(ErrorKey, err) } // WithContext adds a context to the Entry. @@ -182,18 +174,7 @@ func (entry *Entry) WithContext(ctx context.Context) *Entry { func (entry *Entry) WithField(key string, value any) *Entry { dup := entry.dup() dup.Data = maps.Clone(entry.Data) - if isInvalidField(value) { - if dup.err != "" { - dup.err += ", skipping unsupported field " + strconv.Quote(key) - } else { - dup.err = "skipping unsupported field " + strconv.Quote(key) - } - return dup - } - if dup.Data == nil { - dup.Data = make(Fields, 1) - } - dup.Data[key] = value + dup.addField(key, value) return dup } @@ -204,27 +185,11 @@ func (entry *Entry) WithFields(fields Fields) *Entry { maps.Copy(dup.Data, entry.Data) for key, value := range fields { - if isInvalidField(value) { - if dup.err != "" { - dup.err += ", skipping unsupported field " + strconv.Quote(key) - } else { - dup.err = "skipping unsupported field " + strconv.Quote(key) - } - } else { - dup.Data[key] = value - } + dup.addField(key, value) } return dup } -func isInvalidField(v any) bool { - t := reflect.TypeOf(v) - if t == nil { - return false - } - return t.Kind() == reflect.Func || t.Kind() == reflect.Pointer && t.Elem().Kind() == reflect.Func -} - // WithTime overrides the time of the Entry. func (entry *Entry) WithTime(t time.Time) *Entry { dup := entry.dup() @@ -233,6 +198,25 @@ func (entry *Entry) WithTime(t time.Time) *Entry { return dup } +func (entry *Entry) addField(key string, value any) { + if _, ok := value.(error); !ok { + t := reflect.TypeOf(value) + if t != nil && (t.Kind() == reflect.Func || t.Kind() == reflect.Pointer && t.Elem().Kind() == reflect.Func) { + if entry.err != "" { + entry.err += ", skipping unsupported field " + strconv.Quote(key) + } else { + entry.err = "skipping unsupported field " + strconv.Quote(key) + } + return + } + } + + if entry.Data == nil { + entry.Data = make(Fields, 1) + } + entry.Data[key] = value +} + // getPackageName reduces a fully qualified function name to the package name // There really ought to be a better way... func getPackageName(f string) string { diff --git a/vendor/github.com/sirupsen/logrus/exported.go b/vendor/github.com/sirupsen/logrus/exported.go index 844691a94..8b261c124 100644 --- a/vendor/github.com/sirupsen/logrus/exported.go +++ b/vendor/github.com/sirupsen/logrus/exported.go @@ -55,7 +55,7 @@ func AddHook(hook Hook) { // WithError creates an entry from the standard logger and adds an error to it, // using the value defined in [ErrorKey] as key. func WithError(err error) *Entry { - return std.WithField(ErrorKey, err) + return std.WithError(err) } // WithContext creates an entry from the standard logger and adds a context to it. diff --git a/vendor/github.com/sirupsen/logrus/text_formatter.go b/vendor/github.com/sirupsen/logrus/text_formatter.go index 9b0395adf..82c1f3da2 100644 --- a/vendor/github.com/sirupsen/logrus/text_formatter.go +++ b/vendor/github.com/sirupsen/logrus/text_formatter.go @@ -5,6 +5,7 @@ import ( "fmt" "maps" "os" + "reflect" "runtime" "slices" "strconv" @@ -329,10 +330,10 @@ func (f *TextFormatter) appendValue(b *bytes.Buffer, value any) { f.appendBytes(b, strconv.AppendBool(raw[:0], v)) return case error: - f.appendString(b, v.Error()) + f.appendError(b, v) return case fmt.Stringer: - f.appendString(b, v.String()) + f.appendStringer(b, v) return } @@ -417,6 +418,29 @@ func (f *TextFormatter) appendNumeric(b *bytes.Buffer, out []byte) { b.Write(out) } +func (f *TextFormatter) appendError(b *bytes.Buffer, v error) { + defer f.recoverValue(b, v, "Error") + + f.appendString(b, v.Error()) +} + +func (f *TextFormatter) appendStringer(b *bytes.Buffer, v fmt.Stringer) { + defer f.recoverValue(b, v, "String") + + f.appendString(b, v.String()) +} + +func (f *TextFormatter) recoverValue(b *bytes.Buffer, v any, method string) { + if r := recover(); r != nil { + rv := reflect.ValueOf(v) + if rv.Kind() == reflect.Pointer && rv.IsNil() { + f.appendString(b, "") + } else { + f.appendString(b, fmt.Sprintf("%%!v(PANIC=%s method: %v)", method, r)) + } + } +} + // needsQuoting returns true if the string contains any byte that // requires quoting. It returns false when every byte is "safe" according // to isSafeByte. diff --git a/vendor/modules.txt b/vendor/modules.txt index b8854e9d8..aea62c654 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -147,7 +147,7 @@ github.com/prometheus/procfs/internal/util # github.com/russross/blackfriday/v2 v2.1.0 ## explicit github.com/russross/blackfriday/v2 -# github.com/sirupsen/logrus v1.10.0 +# github.com/sirupsen/logrus v1.10.2 ## explicit; go 1.23 github.com/sirupsen/logrus # github.com/spf13/pflag v1.0.10