From 164f7aa1a64acb4ec010b7c0d94f6066780a3a91 Mon Sep 17 00:00:00 2001 From: dils2k Date: Thu, 19 Jan 2023 16:10:08 +0500 Subject: [PATCH 1/6] Add Any field function (#515) --- event.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/event.go b/event.go index eb5c90d..2e736c8 100644 --- a/event.go +++ b/event.go @@ -707,6 +707,11 @@ func (e *Event) TimeDiff(key string, t time.Time, start time.Time) *Event { return e } +// Any is a wrapper around Event.Interface. +func (e *Event) Any(key string, i interface{}) *Event { + return e.Interface(key, i) +} + // Interface adds the field key with i marshaled using reflection. func (e *Event) Interface(key string, i interface{}) *Event { if e == nil { From db221912119df60f20154d5bbc96b6444d6e925d Mon Sep 17 00:00:00 2001 From: Sylvain Rabot Date: Wed, 25 Jan 2023 17:05:09 +0100 Subject: [PATCH 2/6] Use recent go versions in test workflow (#519) Signed-off-by: Sylvain Rabot --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2b9ae77..82a75a4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,17 +4,17 @@ jobs: test: strategy: matrix: - go-version: [1.15.x, 1.16.x] + go-version: [1.18.x, 1.19.x] os: [ubuntu-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - name: Install Go - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: go-version: ${{ matrix.go-version }} - name: Checkout code - uses: actions/checkout@v2 - - uses: actions/cache@v3.0.5 + uses: actions/checkout@v3 + - uses: actions/cache@v3 with: path: ~/go/pkg/mod key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} From fa9bf3742aed687ca8f7d1c73cb834ab68521697 Mon Sep 17 00:00:00 2001 From: Olivier Poitrey Date: Wed, 25 Jan 2023 17:34:40 +0100 Subject: [PATCH 3/6] Fix missing cbor encoder AppendType method --- internal/cbor/types.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/cbor/types.go b/internal/cbor/types.go index 49316aa..6f53832 100644 --- a/internal/cbor/types.go +++ b/internal/cbor/types.go @@ -4,6 +4,7 @@ import ( "fmt" "math" "net" + "reflect" ) // AppendNil inserts a 'Nil' object into the dst byte array. @@ -438,6 +439,14 @@ func (e Encoder) AppendInterface(dst []byte, i interface{}) []byte { return AppendEmbeddedJSON(dst, marshaled) } +// AppendType appends the parameter type (as a string) to the input byte slice. +func (e Encoder) AppendType(dst []byte, i interface{}) []byte { + if i == nil { + return e.AppendString(dst, "") + } + return e.AppendString(dst, reflect.TypeOf(i).String()) +} + // AppendIPAddr encodes and inserts an IP Address (IPv4 or IPv6). func (e Encoder) AppendIPAddr(dst []byte, ip net.IP) []byte { dst = append(dst, majorTypeTags|additionalTypeIntUint16) From 762546b5c64e03f3d23f867213e80aa45906aaf7 Mon Sep 17 00:00:00 2001 From: Adam Chalkley <36716992+atc0005@users.noreply.github.com> Date: Fri, 27 Jan 2023 17:04:14 -0600 Subject: [PATCH 4/6] Replace duplicate 'append' text in doc comments (#520) Replace 'append append' with 'appends'. This resolves what appears to be an unintentional search/replace action that occurred as part of other cleanup work. Co-authored-by: Adam Chalkley --- array.go | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/array.go b/array.go index c75c052..99612ee 100644 --- a/array.go +++ b/array.go @@ -57,7 +57,7 @@ func (a *Array) write(dst []byte) []byte { } // Object marshals an object that implement the LogObjectMarshaler -// interface and append append it to the array. +// interface and appends it to the array. func (a *Array) Object(obj LogObjectMarshaler) *Array { e := Dict() obj.MarshalZerologObject(e) @@ -67,19 +67,19 @@ func (a *Array) Object(obj LogObjectMarshaler) *Array { return a } -// Str append append the val as a string to the array. +// Str appends the val as a string to the array. func (a *Array) Str(val string) *Array { a.buf = enc.AppendString(enc.AppendArrayDelim(a.buf), val) return a } -// Bytes append append the val as a string to the array. +// Bytes appends the val as a string to the array. func (a *Array) Bytes(val []byte) *Array { a.buf = enc.AppendBytes(enc.AppendArrayDelim(a.buf), val) return a } -// Hex append append the val as a hex string to the array. +// Hex appends the val as a hex string to the array. func (a *Array) Hex(val []byte) *Array { a.buf = enc.AppendHex(enc.AppendArrayDelim(a.buf), val) return a @@ -115,97 +115,97 @@ func (a *Array) Err(err error) *Array { return a } -// Bool append append the val as a bool to the array. +// Bool appends the val as a bool to the array. func (a *Array) Bool(b bool) *Array { a.buf = enc.AppendBool(enc.AppendArrayDelim(a.buf), b) return a } -// Int append append i as a int to the array. +// Int appends i as a int to the array. func (a *Array) Int(i int) *Array { a.buf = enc.AppendInt(enc.AppendArrayDelim(a.buf), i) return a } -// Int8 append append i as a int8 to the array. +// Int8 appends i as a int8 to the array. func (a *Array) Int8(i int8) *Array { a.buf = enc.AppendInt8(enc.AppendArrayDelim(a.buf), i) return a } -// Int16 append append i as a int16 to the array. +// Int16 appends i as a int16 to the array. func (a *Array) Int16(i int16) *Array { a.buf = enc.AppendInt16(enc.AppendArrayDelim(a.buf), i) return a } -// Int32 append append i as a int32 to the array. +// Int32 appends i as a int32 to the array. func (a *Array) Int32(i int32) *Array { a.buf = enc.AppendInt32(enc.AppendArrayDelim(a.buf), i) return a } -// Int64 append append i as a int64 to the array. +// Int64 appends i as a int64 to the array. func (a *Array) Int64(i int64) *Array { a.buf = enc.AppendInt64(enc.AppendArrayDelim(a.buf), i) return a } -// Uint append append i as a uint to the array. +// Uint appends i as a uint to the array. func (a *Array) Uint(i uint) *Array { a.buf = enc.AppendUint(enc.AppendArrayDelim(a.buf), i) return a } -// Uint8 append append i as a uint8 to the array. +// Uint8 appends i as a uint8 to the array. func (a *Array) Uint8(i uint8) *Array { a.buf = enc.AppendUint8(enc.AppendArrayDelim(a.buf), i) return a } -// Uint16 append append i as a uint16 to the array. +// Uint16 appends i as a uint16 to the array. func (a *Array) Uint16(i uint16) *Array { a.buf = enc.AppendUint16(enc.AppendArrayDelim(a.buf), i) return a } -// Uint32 append append i as a uint32 to the array. +// Uint32 appends i as a uint32 to the array. func (a *Array) Uint32(i uint32) *Array { a.buf = enc.AppendUint32(enc.AppendArrayDelim(a.buf), i) return a } -// Uint64 append append i as a uint64 to the array. +// Uint64 appends i as a uint64 to the array. func (a *Array) Uint64(i uint64) *Array { a.buf = enc.AppendUint64(enc.AppendArrayDelim(a.buf), i) return a } -// Float32 append append f as a float32 to the array. +// Float32 appends f as a float32 to the array. func (a *Array) Float32(f float32) *Array { a.buf = enc.AppendFloat32(enc.AppendArrayDelim(a.buf), f) return a } -// Float64 append append f as a float64 to the array. +// Float64 appends f as a float64 to the array. func (a *Array) Float64(f float64) *Array { a.buf = enc.AppendFloat64(enc.AppendArrayDelim(a.buf), f) return a } -// Time append append t formatted as string using zerolog.TimeFieldFormat. +// Time appends t formatted as string using zerolog.TimeFieldFormat. func (a *Array) Time(t time.Time) *Array { a.buf = enc.AppendTime(enc.AppendArrayDelim(a.buf), t, TimeFieldFormat) return a } -// Dur append append d to the array. +// Dur appends d to the array. func (a *Array) Dur(d time.Duration) *Array { a.buf = enc.AppendDuration(enc.AppendArrayDelim(a.buf), d, DurationFieldUnit, DurationFieldInteger) return a } -// Interface append append i marshaled using reflection. +// Interface appends i marshaled using reflection. func (a *Array) Interface(i interface{}) *Array { if obj, ok := i.(LogObjectMarshaler); ok { return a.Object(obj) From 4fff5db29c3403bc26dee9895e12a108aacc0203 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Feb 2023 13:02:23 +0100 Subject: [PATCH 5/6] Bump github.com/coreos/go-systemd/v22 (#526) Bumps [github.com/coreos/go-systemd/v22](https://github.com/coreos/go-systemd) from 22.3.3-0.20220203105225-a9a7ef127534 to 22.5.0. - [Release notes](https://github.com/coreos/go-systemd/releases) - [Commits](https://github.com/coreos/go-systemd/commits/v22.5.0) --- updated-dependencies: - dependency-name: github.com/coreos/go-systemd/v22 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- go.mod | 2 +- go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index e5fcd6f..27b9925 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/rs/zerolog go 1.15 require ( - github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534 + github.com/coreos/go-systemd/v22 v22.5.0 github.com/mattn/go-colorable v0.1.12 github.com/pkg/errors v0.9.1 github.com/rs/xid v1.4.0 diff --git a/go.sum b/go.sum index d32e91d..ba05bcb 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534 h1:rtAn27wIbmOGUs7RIbVgPEjb31ehTVniDwPGXyMxm5U= -github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/coreos/go-systemd/v22 v22.5.0 h1:RrqgGjYQKalulkV8NGVIfkXQf6YYmOyiJKk8iXXhfZs= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= From 902d72012db4bb84c7920b5b7f02342381ba39ac Mon Sep 17 00:00:00 2001 From: Menno van Rahden Date: Fri, 10 Mar 2023 16:15:23 +0100 Subject: [PATCH 6/6] fix level parser (#523) --- log.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/log.go b/log.go index c8dbc42..0b51676 100644 --- a/log.go +++ b/log.go @@ -161,24 +161,24 @@ func (l Level) String() string { // ParseLevel converts a level string into a zerolog Level value. // returns an error if the input string does not match known values. func ParseLevel(levelStr string) (Level, error) { - switch strings.ToLower(levelStr) { - case LevelFieldMarshalFunc(TraceLevel): + switch { + case strings.EqualFold(levelStr, LevelFieldMarshalFunc(TraceLevel)): return TraceLevel, nil - case LevelFieldMarshalFunc(DebugLevel): + case strings.EqualFold(levelStr, LevelFieldMarshalFunc(DebugLevel)): return DebugLevel, nil - case LevelFieldMarshalFunc(InfoLevel): + case strings.EqualFold(levelStr, LevelFieldMarshalFunc(InfoLevel)): return InfoLevel, nil - case LevelFieldMarshalFunc(WarnLevel): + case strings.EqualFold(levelStr, LevelFieldMarshalFunc(WarnLevel)): return WarnLevel, nil - case LevelFieldMarshalFunc(ErrorLevel): + case strings.EqualFold(levelStr, LevelFieldMarshalFunc(ErrorLevel)): return ErrorLevel, nil - case LevelFieldMarshalFunc(FatalLevel): + case strings.EqualFold(levelStr, LevelFieldMarshalFunc(FatalLevel)): return FatalLevel, nil - case LevelFieldMarshalFunc(PanicLevel): + case strings.EqualFold(levelStr, LevelFieldMarshalFunc(PanicLevel)): return PanicLevel, nil - case LevelFieldMarshalFunc(Disabled): + case strings.EqualFold(levelStr, LevelFieldMarshalFunc(Disabled)): return Disabled, nil - case LevelFieldMarshalFunc(NoLevel): + case strings.EqualFold(levelStr, LevelFieldMarshalFunc(NoLevel)): return NoLevel, nil } i, err := strconv.Atoi(levelStr)