From fd043ea00460b4b7764e62157930e6cbaa354da3 Mon Sep 17 00:00:00 2001 From: Excavator Bot <33266368+svc-excavator-bot@users.noreply.github.com> Date: Wed, 22 May 2024 22:15:16 -0700 Subject: [PATCH] Excavator: Manage go module dependencies (#361) --- go.mod | 2 +- go.sum | 4 +- vendor/github.com/rs/zerolog/README.md | 18 ++-- vendor/github.com/rs/zerolog/array.go | 6 +- vendor/github.com/rs/zerolog/console.go | 91 +++++++++++++++---- vendor/github.com/rs/zerolog/context.go | 22 +++-- vendor/github.com/rs/zerolog/encoder.go | 12 +-- vendor/github.com/rs/zerolog/event.go | 14 +-- vendor/github.com/rs/zerolog/fields.go | 18 ++-- vendor/github.com/rs/zerolog/globals.go | 24 ++++- .../rs/zerolog/internal/cbor/decode_stream.go | 2 +- .../rs/zerolog/internal/cbor/time.go | 10 +- .../rs/zerolog/internal/cbor/types.go | 12 +-- .../rs/zerolog/internal/json/time.go | 10 +- .../rs/zerolog/internal/json/types.go | 45 ++++++--- vendor/github.com/rs/zerolog/log.go | 2 +- vendor/github.com/rs/zerolog/sampler.go | 2 +- vendor/modules.txt | 2 +- 18 files changed, 195 insertions(+), 101 deletions(-) diff --git a/go.mod b/go.mod index 07dc83be..8e7fe14e 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/palantir/witchcraft-go-error v1.36.0 github.com/palantir/witchcraft-go-params v1.33.0 github.com/palantir/witchcraft-go-tracing v1.35.0 - github.com/rs/zerolog v1.32.0 + github.com/rs/zerolog v1.33.0 github.com/stretchr/testify v1.9.0 go.uber.org/zap v1.15.0 gopkg.in/yaml.v2 v2.4.0 diff --git a/go.sum b/go.sum index 34acdbf0..ece9583c 100644 --- a/go.sum +++ b/go.sum @@ -85,8 +85,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= -github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= -github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= +github.com/rs/zerolog v1.33.0 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8= +github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= diff --git a/vendor/github.com/rs/zerolog/README.md b/vendor/github.com/rs/zerolog/README.md index afa61569..1306a6c1 100644 --- a/vendor/github.com/rs/zerolog/README.md +++ b/vendor/github.com/rs/zerolog/README.md @@ -60,7 +60,7 @@ func main() { // Output: {"time":1516134303,"level":"debug","message":"hello world"} ``` > Note: By default log writes to `os.Stderr` -> Note: The default log level for `log.Print` is *debug* +> Note: The default log level for `log.Print` is *trace* ### Contextual Logging @@ -412,15 +412,7 @@ Equivalent of `Lshortfile`: ```go zerolog.CallerMarshalFunc = func(pc uintptr, file string, line int) string { - short := file - for i := len(file) - 1; i > 0; i-- { - if file[i] == '/' { - short = file[i+1:] - break - } - } - file = short - return file + ":" + strconv.Itoa(line) + return filepath.Base(file) + ":" + strconv.Itoa(line) } log.Logger = log.With().Caller().Logger() log.Info().Msg("hello world") @@ -646,10 +638,14 @@ Some settings can be changed and will be applied to all loggers: * `zerolog.LevelFieldName`: Can be set to customize level field name. * `zerolog.MessageFieldName`: Can be set to customize message field name. * `zerolog.ErrorFieldName`: Can be set to customize `Err` field name. -* `zerolog.TimeFieldFormat`: Can be set to customize `Time` field value formatting. If set with `zerolog.TimeFormatUnix`, `zerolog.TimeFormatUnixMs` or `zerolog.TimeFormatUnixMicro`, times are formated as UNIX timestamp. +* `zerolog.TimeFieldFormat`: Can be set to customize `Time` field value formatting. If set with `zerolog.TimeFormatUnix`, `zerolog.TimeFormatUnixMs` or `zerolog.TimeFormatUnixMicro`, times are formatted as UNIX timestamp. * `zerolog.DurationFieldUnit`: Can be set to customize the unit for time.Duration type fields added by `Dur` (default: `time.Millisecond`). * `zerolog.DurationFieldInteger`: If set to `true`, `Dur` fields are formatted as integers instead of floats (default: `false`). * `zerolog.ErrorHandler`: Called whenever zerolog fails to write an event on its output. If not set, an error is printed on the stderr. This handler must be thread safe and non-blocking. +* `zerolog.FloatingPointPrecision`: If set to a value other than -1, controls the number +of digits when formatting float numbers in JSON. See +[strconv.FormatFloat](https://pkg.go.dev/strconv#FormatFloat) +for more details. ## Field Types diff --git a/vendor/github.com/rs/zerolog/array.go b/vendor/github.com/rs/zerolog/array.go index 99612ee9..ba35b283 100644 --- a/vendor/github.com/rs/zerolog/array.go +++ b/vendor/github.com/rs/zerolog/array.go @@ -183,13 +183,13 @@ func (a *Array) Uint64(i uint64) *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) + a.buf = enc.AppendFloat32(enc.AppendArrayDelim(a.buf), f, FloatingPointPrecision) return a } // 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) + a.buf = enc.AppendFloat64(enc.AppendArrayDelim(a.buf), f, FloatingPointPrecision) return a } @@ -201,7 +201,7 @@ func (a *Array) Time(t time.Time) *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) + a.buf = enc.AppendDuration(enc.AppendArrayDelim(a.buf), d, DurationFieldUnit, DurationFieldInteger, FloatingPointPrecision) return a } diff --git a/vendor/github.com/rs/zerolog/console.go b/vendor/github.com/rs/zerolog/console.go index cc6d623e..7e65e86f 100644 --- a/vendor/github.com/rs/zerolog/console.go +++ b/vendor/github.com/rs/zerolog/console.go @@ -28,6 +28,8 @@ const ( colorBold = 1 colorDarkGray = 90 + + unknownLevel = "???" ) var ( @@ -57,12 +59,21 @@ type ConsoleWriter struct { // TimeFormat specifies the format for timestamp in output. TimeFormat string + // TimeLocation tells ConsoleWriter’s default FormatTimestamp + // how to localize the time. + TimeLocation *time.Location + // PartsOrder defines the order of parts in output. PartsOrder []string // PartsExclude defines parts to not display in output. PartsExclude []string + // FieldsOrder defines the order of contextual fields in output. + FieldsOrder []string + + fieldIsOrdered map[string]int + // FieldsExclude defines contextual fields to not display in output. FieldsExclude []string @@ -83,9 +94,9 @@ type ConsoleWriter struct { // NewConsoleWriter creates and initializes a new ConsoleWriter. func NewConsoleWriter(options ...func(w *ConsoleWriter)) ConsoleWriter { w := ConsoleWriter{ - Out: os.Stdout, - TimeFormat: consoleDefaultTimeFormat, - PartsOrder: consoleDefaultPartsOrder(), + Out: os.Stdout, + TimeFormat: consoleDefaultTimeFormat, + PartsOrder: consoleDefaultPartsOrder(), } for _, opt := range options { @@ -185,7 +196,12 @@ func (w ConsoleWriter) writeFields(evt map[string]interface{}, buf *bytes.Buffer } fields = append(fields, field) } - sort.Strings(fields) + + if len(w.FieldsOrder) > 0 { + w.orderFields(fields) + } else { + sort.Strings(fields) + } // Write space only if something has already been written to the buffer, and if there are fields. if buf.Len() > 0 && len(fields) > 0 { @@ -284,7 +300,7 @@ func (w ConsoleWriter) writePart(buf *bytes.Buffer, evt map[string]interface{}, } case TimestampFieldName: if w.FormatTimestamp == nil { - f = consoleDefaultFormatTimestamp(w.TimeFormat, w.NoColor) + f = consoleDefaultFormatTimestamp(w.TimeFormat, w.TimeLocation, w.NoColor) } else { f = w.FormatTimestamp } @@ -318,6 +334,32 @@ func (w ConsoleWriter) writePart(buf *bytes.Buffer, evt map[string]interface{}, } } +// orderFields takes an array of field names and an array representing field order +// and returns an array with any ordered fields at the beginning, in order, +// and the remaining fields after in their original order. +func (w ConsoleWriter) orderFields(fields []string) { + if w.fieldIsOrdered == nil { + w.fieldIsOrdered = make(map[string]int) + for i, fieldName := range w.FieldsOrder { + w.fieldIsOrdered[fieldName] = i + } + } + sort.Slice(fields, func(i, j int) bool { + ii, iOrdered := w.fieldIsOrdered[fields[i]] + jj, jOrdered := w.fieldIsOrdered[fields[j]] + if iOrdered && jOrdered { + return ii < jj + } + if iOrdered { + return true + } + if jOrdered { + return false + } + return fields[i] < fields[j] + }) +} + // needsQuote returns true when the string s should be quoted in output. func needsQuote(s string) bool { for i := range s { @@ -352,19 +394,23 @@ func consoleDefaultPartsOrder() []string { } } -func consoleDefaultFormatTimestamp(timeFormat string, noColor bool) Formatter { +func consoleDefaultFormatTimestamp(timeFormat string, location *time.Location, noColor bool) Formatter { if timeFormat == "" { timeFormat = consoleDefaultTimeFormat } + if location == nil { + location = time.Local + } + return func(i interface{}) string { t := "" switch tt := i.(type) { case string: - ts, err := time.ParseInLocation(TimeFieldFormat, tt, time.Local) + ts, err := time.ParseInLocation(TimeFieldFormat, tt, location) if err != nil { t = tt } else { - t = ts.Local().Format(timeFormat) + t = ts.In(location).Format(timeFormat) } case json.Number: i, err := tt.Int64() @@ -385,32 +431,37 @@ func consoleDefaultFormatTimestamp(timeFormat string, noColor bool) Formatter { } ts := time.Unix(sec, nsec) - t = ts.Format(timeFormat) + t = ts.In(location).Format(timeFormat) } } return colorize(t, colorDarkGray, noColor) } } +func stripLevel(ll string) string { + if len(ll) == 0 { + return unknownLevel + } + if len(ll) > 3 { + ll = ll[:3] + } + return strings.ToUpper(ll) +} + func consoleDefaultFormatLevel(noColor bool) Formatter { return func(i interface{}) string { - var l string if ll, ok := i.(string); ok { level, _ := ParseLevel(ll) fl, ok := FormattedLevels[level] if ok { - l = colorize(fl, LevelColors[level], noColor) - } else { - l = strings.ToUpper(ll)[0:3] - } - } else { - if i == nil { - l = "???" - } else { - l = strings.ToUpper(fmt.Sprintf("%s", i))[0:3] + return colorize(fl, LevelColors[level], noColor) } + return stripLevel(ll) + } + if i == nil { + return unknownLevel } - return l + return stripLevel(fmt.Sprintf("%s", i)) } } diff --git a/vendor/github.com/rs/zerolog/context.go b/vendor/github.com/rs/zerolog/context.go index df352eb6..ff9a3ae2 100644 --- a/vendor/github.com/rs/zerolog/context.go +++ b/vendor/github.com/rs/zerolog/context.go @@ -325,25 +325,25 @@ func (c Context) Uints64(key string, i []uint64) Context { // Float32 adds the field key with f as a float32 to the logger context. func (c Context) Float32(key string, f float32) Context { - c.l.context = enc.AppendFloat32(enc.AppendKey(c.l.context, key), f) + c.l.context = enc.AppendFloat32(enc.AppendKey(c.l.context, key), f, FloatingPointPrecision) return c } // Floats32 adds the field key with f as a []float32 to the logger context. func (c Context) Floats32(key string, f []float32) Context { - c.l.context = enc.AppendFloats32(enc.AppendKey(c.l.context, key), f) + c.l.context = enc.AppendFloats32(enc.AppendKey(c.l.context, key), f, FloatingPointPrecision) return c } // Float64 adds the field key with f as a float64 to the logger context. func (c Context) Float64(key string, f float64) Context { - c.l.context = enc.AppendFloat64(enc.AppendKey(c.l.context, key), f) + c.l.context = enc.AppendFloat64(enc.AppendKey(c.l.context, key), f, FloatingPointPrecision) return c } // Floats64 adds the field key with f as a []float64 to the logger context. func (c Context) Floats64(key string, f []float64) Context { - c.l.context = enc.AppendFloats64(enc.AppendKey(c.l.context, key), f) + c.l.context = enc.AppendFloats64(enc.AppendKey(c.l.context, key), f, FloatingPointPrecision) return c } @@ -365,13 +365,13 @@ func (c Context) Timestamp() Context { return c } -// Time adds the field key with t formated as string using zerolog.TimeFieldFormat. +// Time adds the field key with t formatted as string using zerolog.TimeFieldFormat. func (c Context) Time(key string, t time.Time) Context { c.l.context = enc.AppendTime(enc.AppendKey(c.l.context, key), t, TimeFieldFormat) return c } -// Times adds the field key with t formated as string using zerolog.TimeFieldFormat. +// Times adds the field key with t formatted as string using zerolog.TimeFieldFormat. func (c Context) Times(key string, t []time.Time) Context { c.l.context = enc.AppendTimes(enc.AppendKey(c.l.context, key), t, TimeFieldFormat) return c @@ -379,13 +379,13 @@ func (c Context) Times(key string, t []time.Time) Context { // Dur adds the fields key with d divided by unit and stored as a float. func (c Context) Dur(key string, d time.Duration) Context { - c.l.context = enc.AppendDuration(enc.AppendKey(c.l.context, key), d, DurationFieldUnit, DurationFieldInteger) + c.l.context = enc.AppendDuration(enc.AppendKey(c.l.context, key), d, DurationFieldUnit, DurationFieldInteger, FloatingPointPrecision) return c } // Durs adds the fields key with d divided by unit and stored as a float. func (c Context) Durs(key string, d []time.Duration) Context { - c.l.context = enc.AppendDurations(enc.AppendKey(c.l.context, key), d, DurationFieldUnit, DurationFieldInteger) + c.l.context = enc.AppendDurations(enc.AppendKey(c.l.context, key), d, DurationFieldUnit, DurationFieldInteger, FloatingPointPrecision) return c } @@ -409,6 +409,12 @@ func (c Context) Any(key string, i interface{}) Context { return c.Interface(key, i) } +// Reset removes all the context fields. +func (c Context) Reset() Context { + c.l.context = enc.AppendBeginMarker(make([]byte, 0, 500)) + return c +} + type callerHook struct { callerSkipFrameCount int } diff --git a/vendor/github.com/rs/zerolog/encoder.go b/vendor/github.com/rs/zerolog/encoder.go index 09b24e80..4dbaf380 100644 --- a/vendor/github.com/rs/zerolog/encoder.go +++ b/vendor/github.com/rs/zerolog/encoder.go @@ -13,13 +13,13 @@ type encoder interface { AppendBool(dst []byte, val bool) []byte AppendBools(dst []byte, vals []bool) []byte AppendBytes(dst, s []byte) []byte - AppendDuration(dst []byte, d time.Duration, unit time.Duration, useInt bool) []byte - AppendDurations(dst []byte, vals []time.Duration, unit time.Duration, useInt bool) []byte + AppendDuration(dst []byte, d time.Duration, unit time.Duration, useInt bool, precision int) []byte + AppendDurations(dst []byte, vals []time.Duration, unit time.Duration, useInt bool, precision int) []byte AppendEndMarker(dst []byte) []byte - AppendFloat32(dst []byte, val float32) []byte - AppendFloat64(dst []byte, val float64) []byte - AppendFloats32(dst []byte, vals []float32) []byte - AppendFloats64(dst []byte, vals []float64) []byte + AppendFloat32(dst []byte, val float32, precision int) []byte + AppendFloat64(dst []byte, val float64, precision int) []byte + AppendFloats32(dst []byte, vals []float32, precision int) []byte + AppendFloats64(dst []byte, vals []float64, precision int) []byte AppendHex(dst, s []byte) []byte AppendIPAddr(dst []byte, ip net.IP) []byte AppendIPPrefix(dst []byte, pfx net.IPNet) []byte diff --git a/vendor/github.com/rs/zerolog/event.go b/vendor/github.com/rs/zerolog/event.go index 5c949f8a..56de6061 100644 --- a/vendor/github.com/rs/zerolog/event.go +++ b/vendor/github.com/rs/zerolog/event.go @@ -644,7 +644,7 @@ func (e *Event) Float32(key string, f float32) *Event { if e == nil { return e } - e.buf = enc.AppendFloat32(enc.AppendKey(e.buf, key), f) + e.buf = enc.AppendFloat32(enc.AppendKey(e.buf, key), f, FloatingPointPrecision) return e } @@ -653,7 +653,7 @@ func (e *Event) Floats32(key string, f []float32) *Event { if e == nil { return e } - e.buf = enc.AppendFloats32(enc.AppendKey(e.buf, key), f) + e.buf = enc.AppendFloats32(enc.AppendKey(e.buf, key), f, FloatingPointPrecision) return e } @@ -662,7 +662,7 @@ func (e *Event) Float64(key string, f float64) *Event { if e == nil { return e } - e.buf = enc.AppendFloat64(enc.AppendKey(e.buf, key), f) + e.buf = enc.AppendFloat64(enc.AppendKey(e.buf, key), f, FloatingPointPrecision) return e } @@ -671,7 +671,7 @@ func (e *Event) Floats64(key string, f []float64) *Event { if e == nil { return e } - e.buf = enc.AppendFloats64(enc.AppendKey(e.buf, key), f) + e.buf = enc.AppendFloats64(enc.AppendKey(e.buf, key), f, FloatingPointPrecision) return e } @@ -713,7 +713,7 @@ func (e *Event) Dur(key string, d time.Duration) *Event { if e == nil { return e } - e.buf = enc.AppendDuration(enc.AppendKey(e.buf, key), d, DurationFieldUnit, DurationFieldInteger) + e.buf = enc.AppendDuration(enc.AppendKey(e.buf, key), d, DurationFieldUnit, DurationFieldInteger, FloatingPointPrecision) return e } @@ -724,7 +724,7 @@ func (e *Event) Durs(key string, d []time.Duration) *Event { if e == nil { return e } - e.buf = enc.AppendDurations(enc.AppendKey(e.buf, key), d, DurationFieldUnit, DurationFieldInteger) + e.buf = enc.AppendDurations(enc.AppendKey(e.buf, key), d, DurationFieldUnit, DurationFieldInteger, FloatingPointPrecision) return e } @@ -739,7 +739,7 @@ func (e *Event) TimeDiff(key string, t time.Time, start time.Time) *Event { if t.After(start) { d = t.Sub(start) } - e.buf = enc.AppendDuration(enc.AppendKey(e.buf, key), d, DurationFieldUnit, DurationFieldInteger) + e.buf = enc.AppendDuration(enc.AppendKey(e.buf, key), d, DurationFieldUnit, DurationFieldInteger, FloatingPointPrecision) return e } diff --git a/vendor/github.com/rs/zerolog/fields.go b/vendor/github.com/rs/zerolog/fields.go index 23606ddd..99f52718 100644 --- a/vendor/github.com/rs/zerolog/fields.go +++ b/vendor/github.com/rs/zerolog/fields.go @@ -139,13 +139,13 @@ func appendFieldList(dst []byte, kvList []interface{}, stack bool) []byte { case uint64: dst = enc.AppendUint64(dst, val) case float32: - dst = enc.AppendFloat32(dst, val) + dst = enc.AppendFloat32(dst, val, FloatingPointPrecision) case float64: - dst = enc.AppendFloat64(dst, val) + dst = enc.AppendFloat64(dst, val, FloatingPointPrecision) case time.Time: dst = enc.AppendTime(dst, val, TimeFieldFormat) case time.Duration: - dst = enc.AppendDuration(dst, val, DurationFieldUnit, DurationFieldInteger) + dst = enc.AppendDuration(dst, val, DurationFieldUnit, DurationFieldInteger, FloatingPointPrecision) case *string: if val != nil { dst = enc.AppendString(dst, *val) @@ -220,13 +220,13 @@ func appendFieldList(dst []byte, kvList []interface{}, stack bool) []byte { } case *float32: if val != nil { - dst = enc.AppendFloat32(dst, *val) + dst = enc.AppendFloat32(dst, *val, FloatingPointPrecision) } else { dst = enc.AppendNil(dst) } case *float64: if val != nil { - dst = enc.AppendFloat64(dst, *val) + dst = enc.AppendFloat64(dst, *val, FloatingPointPrecision) } else { dst = enc.AppendNil(dst) } @@ -238,7 +238,7 @@ func appendFieldList(dst []byte, kvList []interface{}, stack bool) []byte { } case *time.Duration: if val != nil { - dst = enc.AppendDuration(dst, *val, DurationFieldUnit, DurationFieldInteger) + dst = enc.AppendDuration(dst, *val, DurationFieldUnit, DurationFieldInteger, FloatingPointPrecision) } else { dst = enc.AppendNil(dst) } @@ -267,13 +267,13 @@ func appendFieldList(dst []byte, kvList []interface{}, stack bool) []byte { case []uint64: dst = enc.AppendUints64(dst, val) case []float32: - dst = enc.AppendFloats32(dst, val) + dst = enc.AppendFloats32(dst, val, FloatingPointPrecision) case []float64: - dst = enc.AppendFloats64(dst, val) + dst = enc.AppendFloats64(dst, val, FloatingPointPrecision) case []time.Time: dst = enc.AppendTimes(dst, val, TimeFieldFormat) case []time.Duration: - dst = enc.AppendDurations(dst, val, DurationFieldUnit, DurationFieldInteger) + dst = enc.AppendDurations(dst, val, DurationFieldUnit, DurationFieldInteger, FloatingPointPrecision) case nil: dst = enc.AppendNil(dst) case net.IP: diff --git a/vendor/github.com/rs/zerolog/globals.go b/vendor/github.com/rs/zerolog/globals.go index b38a7fce..9a9be713 100644 --- a/vendor/github.com/rs/zerolog/globals.go +++ b/vendor/github.com/rs/zerolog/globals.go @@ -1,6 +1,7 @@ package zerolog import ( + "bytes" "encoding/json" "strconv" "sync/atomic" @@ -81,8 +82,22 @@ var ( } // InterfaceMarshalFunc allows customization of interface marshaling. - // Default: "encoding/json.Marshal" - InterfaceMarshalFunc = json.Marshal + // Default: "encoding/json.Marshal" with disabled HTML escaping + InterfaceMarshalFunc = func(v interface{}) ([]byte, error) { + var buf bytes.Buffer + encoder := json.NewEncoder(&buf) + encoder.SetEscapeHTML(false) + err := encoder.Encode(v) + if err != nil { + return nil, err + } + b := buf.Bytes() + if len(b) > 0 { + // Remove trailing \n which is added by Encode. + return b[:len(b)-1], nil + } + return b, nil + } // TimeFieldFormat defines the time format of the Time field type. If set to // TimeFormatUnix, TimeFormatUnixMs, TimeFormatUnixMicro or TimeFormatUnixNano, the time is formatted as a UNIX @@ -136,6 +151,11 @@ var ( // TriggerLevelWriterBufferReuseLimit is a limit in bytes that a buffer is dropped // from the TriggerLevelWriter buffer pool if the buffer grows above the limit. TriggerLevelWriterBufferReuseLimit = 64 * 1024 + + // FloatingPointPrecision, if set to a value other than -1, controls the number + // of digits when formatting float numbers in JSON. See strconv.FormatFloat for + // more details. + FloatingPointPrecision = -1 ) var ( diff --git a/vendor/github.com/rs/zerolog/internal/cbor/decode_stream.go b/vendor/github.com/rs/zerolog/internal/cbor/decode_stream.go index 616bed65..5633e666 100644 --- a/vendor/github.com/rs/zerolog/internal/cbor/decode_stream.go +++ b/vendor/github.com/rs/zerolog/internal/cbor/decode_stream.go @@ -95,7 +95,7 @@ func decodeFloat(src *bufio.Reader) (float64, int) { switch minor { case additionalTypeFloat16: - panic(fmt.Errorf("float16 is not suppported in decodeFloat")) + panic(fmt.Errorf("float16 is not supported in decodeFloat")) case additionalTypeFloat32: pb := readNBytes(src, 4) diff --git a/vendor/github.com/rs/zerolog/internal/cbor/time.go b/vendor/github.com/rs/zerolog/internal/cbor/time.go index d81fb125..7c0eccee 100644 --- a/vendor/github.com/rs/zerolog/internal/cbor/time.go +++ b/vendor/github.com/rs/zerolog/internal/cbor/time.go @@ -29,7 +29,7 @@ func (e Encoder) appendFloatTimestamp(dst []byte, t time.Time) []byte { nanos := t.Nanosecond() var val float64 val = float64(secs)*1.0 + float64(nanos)*1e-9 - return e.AppendFloat64(dst, val) + return e.AppendFloat64(dst, val, -1) } // AppendTime encodes and adds a timestamp to the dst byte array. @@ -64,17 +64,17 @@ func (e Encoder) AppendTimes(dst []byte, vals []time.Time, unused string) []byte // AppendDuration encodes and adds a duration to the dst byte array. // useInt field indicates whether to store the duration as seconds (integer) or // as seconds+nanoseconds (float). -func (e Encoder) AppendDuration(dst []byte, d time.Duration, unit time.Duration, useInt bool) []byte { +func (e Encoder) AppendDuration(dst []byte, d time.Duration, unit time.Duration, useInt bool, unused int) []byte { if useInt { return e.AppendInt64(dst, int64(d/unit)) } - return e.AppendFloat64(dst, float64(d)/float64(unit)) + return e.AppendFloat64(dst, float64(d)/float64(unit), unused) } // AppendDurations encodes and adds an array of durations to the dst byte array. // useInt field indicates whether to store the duration as seconds (integer) or // as seconds+nanoseconds (float). -func (e Encoder) AppendDurations(dst []byte, vals []time.Duration, unit time.Duration, useInt bool) []byte { +func (e Encoder) AppendDurations(dst []byte, vals []time.Duration, unit time.Duration, useInt bool, unused int) []byte { major := majorTypeArray l := len(vals) if l == 0 { @@ -87,7 +87,7 @@ func (e Encoder) AppendDurations(dst []byte, vals []time.Duration, unit time.Dur dst = appendCborTypePrefix(dst, major, uint64(l)) } for _, d := range vals { - dst = e.AppendDuration(dst, d, unit, useInt) + dst = e.AppendDuration(dst, d, unit, useInt, unused) } return dst } diff --git a/vendor/github.com/rs/zerolog/internal/cbor/types.go b/vendor/github.com/rs/zerolog/internal/cbor/types.go index 6f538328..454d68bd 100644 --- a/vendor/github.com/rs/zerolog/internal/cbor/types.go +++ b/vendor/github.com/rs/zerolog/internal/cbor/types.go @@ -352,7 +352,7 @@ func (e Encoder) AppendUints64(dst []byte, vals []uint64) []byte { } // AppendFloat32 encodes and inserts a single precision float value into the dst byte array. -func (Encoder) AppendFloat32(dst []byte, val float32) []byte { +func (Encoder) AppendFloat32(dst []byte, val float32, unused int) []byte { switch { case math.IsNaN(float64(val)): return append(dst, "\xfa\x7f\xc0\x00\x00"...) @@ -372,7 +372,7 @@ func (Encoder) AppendFloat32(dst []byte, val float32) []byte { } // AppendFloats32 encodes and inserts an array of single precision float value into the dst byte array. -func (e Encoder) AppendFloats32(dst []byte, vals []float32) []byte { +func (e Encoder) AppendFloats32(dst []byte, vals []float32, unused int) []byte { major := majorTypeArray l := len(vals) if l == 0 { @@ -385,13 +385,13 @@ func (e Encoder) AppendFloats32(dst []byte, vals []float32) []byte { dst = appendCborTypePrefix(dst, major, uint64(l)) } for _, v := range vals { - dst = e.AppendFloat32(dst, v) + dst = e.AppendFloat32(dst, v, unused) } return dst } // AppendFloat64 encodes and inserts a double precision float value into the dst byte array. -func (Encoder) AppendFloat64(dst []byte, val float64) []byte { +func (Encoder) AppendFloat64(dst []byte, val float64, unused int) []byte { switch { case math.IsNaN(val): return append(dst, "\xfb\x7f\xf8\x00\x00\x00\x00\x00\x00"...) @@ -412,7 +412,7 @@ func (Encoder) AppendFloat64(dst []byte, val float64) []byte { } // AppendFloats64 encodes and inserts an array of double precision float values into the dst byte array. -func (e Encoder) AppendFloats64(dst []byte, vals []float64) []byte { +func (e Encoder) AppendFloats64(dst []byte, vals []float64, unused int) []byte { major := majorTypeArray l := len(vals) if l == 0 { @@ -425,7 +425,7 @@ func (e Encoder) AppendFloats64(dst []byte, vals []float64) []byte { dst = appendCborTypePrefix(dst, major, uint64(l)) } for _, v := range vals { - dst = e.AppendFloat64(dst, v) + dst = e.AppendFloat64(dst, v, unused) } return dst } diff --git a/vendor/github.com/rs/zerolog/internal/json/time.go b/vendor/github.com/rs/zerolog/internal/json/time.go index 6a8dc912..08cbbd9b 100644 --- a/vendor/github.com/rs/zerolog/internal/json/time.go +++ b/vendor/github.com/rs/zerolog/internal/json/time.go @@ -88,24 +88,24 @@ func appendUnixNanoTimes(dst []byte, vals []time.Time, div int64) []byte { // AppendDuration formats the input duration with the given unit & format // and appends the encoded string to the input byte slice. -func (e Encoder) AppendDuration(dst []byte, d time.Duration, unit time.Duration, useInt bool) []byte { +func (e Encoder) AppendDuration(dst []byte, d time.Duration, unit time.Duration, useInt bool, precision int) []byte { if useInt { return strconv.AppendInt(dst, int64(d/unit), 10) } - return e.AppendFloat64(dst, float64(d)/float64(unit)) + return e.AppendFloat64(dst, float64(d)/float64(unit), precision) } // AppendDurations formats the input durations with the given unit & format // and appends the encoded string list to the input byte slice. -func (e Encoder) AppendDurations(dst []byte, vals []time.Duration, unit time.Duration, useInt bool) []byte { +func (e Encoder) AppendDurations(dst []byte, vals []time.Duration, unit time.Duration, useInt bool, precision int) []byte { if len(vals) == 0 { return append(dst, '[', ']') } dst = append(dst, '[') - dst = e.AppendDuration(dst, vals[0], unit, useInt) + dst = e.AppendDuration(dst, vals[0], unit, useInt, precision) if len(vals) > 1 { for _, d := range vals[1:] { - dst = e.AppendDuration(append(dst, ','), d, unit, useInt) + dst = e.AppendDuration(append(dst, ','), d, unit, useInt, precision) } } dst = append(dst, ']') diff --git a/vendor/github.com/rs/zerolog/internal/json/types.go b/vendor/github.com/rs/zerolog/internal/json/types.go index ef3a2a7a..7930491a 100644 --- a/vendor/github.com/rs/zerolog/internal/json/types.go +++ b/vendor/github.com/rs/zerolog/internal/json/types.go @@ -299,7 +299,7 @@ func (Encoder) AppendUints64(dst []byte, vals []uint64) []byte { return dst } -func appendFloat(dst []byte, val float64, bitSize int) []byte { +func appendFloat(dst []byte, val float64, bitSize, precision int) []byte { // JSON does not permit NaN or Infinity. A typical JSON encoder would fail // with an error, but a logging library wants the data to get through so we // make a tradeoff and store those types as string. @@ -311,26 +311,47 @@ func appendFloat(dst []byte, val float64, bitSize int) []byte { case math.IsInf(val, -1): return append(dst, `"-Inf"`...) } - return strconv.AppendFloat(dst, val, 'f', -1, bitSize) + // convert as if by es6 number to string conversion + // see also https://cs.opensource.google/go/go/+/refs/tags/go1.20.3:src/encoding/json/encode.go;l=573 + strFmt := byte('f') + // If precision is set to a value other than -1, we always just format the float using that precision. + if precision == -1 { + // Use float32 comparisons for underlying float32 value to get precise cutoffs right. + if abs := math.Abs(val); abs != 0 { + if bitSize == 64 && (abs < 1e-6 || abs >= 1e21) || bitSize == 32 && (float32(abs) < 1e-6 || float32(abs) >= 1e21) { + strFmt = 'e' + } + } + } + dst = strconv.AppendFloat(dst, val, strFmt, precision, bitSize) + if strFmt == 'e' { + // Clean up e-09 to e-9 + n := len(dst) + if n >= 4 && dst[n-4] == 'e' && dst[n-3] == '-' && dst[n-2] == '0' { + dst[n-2] = dst[n-1] + dst = dst[:n-1] + } + } + return dst } // AppendFloat32 converts the input float32 to a string and // appends the encoded string to the input byte slice. -func (Encoder) AppendFloat32(dst []byte, val float32) []byte { - return appendFloat(dst, float64(val), 32) +func (Encoder) AppendFloat32(dst []byte, val float32, precision int) []byte { + return appendFloat(dst, float64(val), 32, precision) } // AppendFloats32 encodes the input float32s to json and // appends the encoded string list to the input byte slice. -func (Encoder) AppendFloats32(dst []byte, vals []float32) []byte { +func (Encoder) AppendFloats32(dst []byte, vals []float32, precision int) []byte { if len(vals) == 0 { return append(dst, '[', ']') } dst = append(dst, '[') - dst = appendFloat(dst, float64(vals[0]), 32) + dst = appendFloat(dst, float64(vals[0]), 32, precision) if len(vals) > 1 { for _, val := range vals[1:] { - dst = appendFloat(append(dst, ','), float64(val), 32) + dst = appendFloat(append(dst, ','), float64(val), 32, precision) } } dst = append(dst, ']') @@ -339,21 +360,21 @@ func (Encoder) AppendFloats32(dst []byte, vals []float32) []byte { // AppendFloat64 converts the input float64 to a string and // appends the encoded string to the input byte slice. -func (Encoder) AppendFloat64(dst []byte, val float64) []byte { - return appendFloat(dst, val, 64) +func (Encoder) AppendFloat64(dst []byte, val float64, precision int) []byte { + return appendFloat(dst, val, 64, precision) } // AppendFloats64 encodes the input float64s to json and // appends the encoded string list to the input byte slice. -func (Encoder) AppendFloats64(dst []byte, vals []float64) []byte { +func (Encoder) AppendFloats64(dst []byte, vals []float64, precision int) []byte { if len(vals) == 0 { return append(dst, '[', ']') } dst = append(dst, '[') - dst = appendFloat(dst, vals[0], 64) + dst = appendFloat(dst, vals[0], 64, precision) if len(vals) > 1 { for _, val := range vals[1:] { - dst = appendFloat(append(dst, ','), val, 64) + dst = appendFloat(append(dst, ','), val, 64, precision) } } dst = append(dst, ']') diff --git a/vendor/github.com/rs/zerolog/log.go b/vendor/github.com/rs/zerolog/log.go index 9fec7cc3..6c1d4ead 100644 --- a/vendor/github.com/rs/zerolog/log.go +++ b/vendor/github.com/rs/zerolog/log.go @@ -24,7 +24,7 @@ // // Sub-loggers let you chain loggers with additional context: // -// sublogger := log.With().Str("component": "foo").Logger() +// sublogger := log.With().Str("component", "foo").Logger() // sublogger.Info().Msg("hello world") // // Output: {"time":1494567715,"level":"info","message":"hello world","component":"foo"} // diff --git a/vendor/github.com/rs/zerolog/sampler.go b/vendor/github.com/rs/zerolog/sampler.go index 1be98c4f..83ce2ed3 100644 --- a/vendor/github.com/rs/zerolog/sampler.go +++ b/vendor/github.com/rs/zerolog/sampler.go @@ -84,7 +84,7 @@ func (s *BurstSampler) Sample(lvl Level) bool { } func (s *BurstSampler) inc() uint32 { - now := time.Now().UnixNano() + now := TimestampFunc().UnixNano() resetAt := atomic.LoadInt64(&s.resetAt) var c uint32 if now > resetAt { diff --git a/vendor/modules.txt b/vendor/modules.txt index 5d660ed2..1a77a6b1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -67,7 +67,7 @@ github.com/palantir/witchcraft-go-tracing/wzipkin # github.com/pmezard/go-difflib v1.0.0 ## explicit github.com/pmezard/go-difflib/difflib -# github.com/rs/zerolog v1.32.0 +# github.com/rs/zerolog v1.33.0 ## explicit; go 1.15 github.com/rs/zerolog github.com/rs/zerolog/internal/cbor