chore(deps): update module github.com/rs/zerolog to v1.34.0 #13

Open
renovate wants to merge 1 commit from renovate/github.com-rs-zerolog-1.x into main
11 changed files with 113 additions and 11 deletions

2
go.mod
View file

@ -5,7 +5,7 @@ go 1.21
require ( require (
github.com/aws/aws-sdk-go v1.55.5 github.com/aws/aws-sdk-go v1.55.5
github.com/pkg/sftp v1.13.6 github.com/pkg/sftp v1.13.6
github.com/rs/zerolog v1.33.0 github.com/rs/zerolog v1.34.0
github.com/stretchr/testify v1.9.0 github.com/stretchr/testify v1.9.0
github.com/urfave/cli/v2 v2.27.4 github.com/urfave/cli/v2 v2.27.4
golang.org/x/crypto v0.27.0 golang.org/x/crypto v0.27.0

3
go.sum
View file

@ -28,10 +28,13 @@ github.com/pkg/sftp v1.13.6/go.mod h1:tz1ryNURKu77RL+GuCzmoJYxQczL3wLNNpPWagdg4Q
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/rs/zerolog v1.31.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 h1:1cU2KZkvPxNyfgEmhHAz/1A9Bz+llsdYzklWFzgp0r8=
github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/rs/zerolog v1.33.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= 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/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

1
vendor/github.com/rs/zerolog/CNAME generated vendored
View file

@ -1 +0,0 @@
zerolog.io

43
vendor/github.com/rs/zerolog/CONTRIBUTING.md generated vendored Normal file
View file

@ -0,0 +1,43 @@
# Contributing to Zerolog
Thank you for your interest in contributing to **Zerolog**!
Zerolog is a **feature-complete**, high-performance logging library designed to be **lean** and **non-bloated**. The focus of ongoing development is on **bug fixes**, **performance improvements**, and **modernization efforts** (such as keeping up with Go best practices and compatibility with newer Go versions).
## What We're Looking For
We welcome contributions in the following areas:
- **Bug Fixes**: If you find an issue or unexpected behavior, please open an issue and/or submit a fix.
- **Performance Optimizations**: Improvements that reduce memory usage, allocation count, or CPU cycles without introducing complexity are appreciated.
- **Modernization**: Compatibility updates for newer Go versions or idiomatic improvements that do not increase library size or complexity.
- **Documentation Enhancements**: Corrections, clarifications, and improvements to documentation or code comments.
## What We're *Not* Looking For
Zerolog is intended to remain **minimalistic and efficient**. Therefore, we are **not accepting**:
- New features that add optional behaviors or extend API surface area.
- Built-in support for frameworks or external systems (e.g., bindings, integrations).
- General-purpose abstractions or configuration helpers.
If you're unsure whether a change aligns with the project's philosophy, feel free to open an issue for discussion before submitting a PR.
## Contributing Guidelines
1. **Fork the repository**
2. **Create a branch** for your fix or improvement
3. **Write tests** to cover your changes
4. Ensure `go test ./...` passes
5. Run `go fmt` and `go vet` to ensure code consistency
6. **Submit a pull request** with a clear explanation of the motivation and impact
## Code Style
- Keep the code simple, efficient, and idiomatic.
- Avoid introducing new dependencies.
- Preserve backwards compatibility unless explicitly discussed.
---
We appreciate your effort in helping us keep Zerolog fast, minimal, and reliable!

View file

@ -366,6 +366,37 @@ log.Info().Str("foo", "bar").Msg("Hello World")
// Output: 2006-01-02T15:04:05Z07:00 | INFO | ***Hello World**** foo:BAR // Output: 2006-01-02T15:04:05Z07:00 | INFO | ***Hello World**** foo:BAR
``` ```
To use custom advanced formatting:
```go
output := zerolog.ConsoleWriter{Out: os.Stdout, NoColor: true,
PartsOrder: []string{"level", "one", "two", "three", "message"},
FieldsExclude: []string{"one", "two", "three"}}
output.FormatLevel = func(i interface{}) string { return strings.ToUpper(fmt.Sprintf("%-6s", i)) }
output.FormatFieldName = func(i interface{}) string { return fmt.Sprintf("%s:", i) }
output.FormatPartValueByName = func(i interface{}, s string) string {
var ret string
switch s {
case "one":
ret = strings.ToUpper(fmt.Sprintf("%s", i))
case "two":
ret = strings.ToLower(fmt.Sprintf("%s", i))
case "three":
ret = strings.ToLower(fmt.Sprintf("(%s)", i))
}
return ret
}
log := zerolog.New(output)
log.Info().Str("foo", "bar").
Str("two", "TEST_TWO").
Str("one", "test_one").
Str("three", "test_three").
Msg("Hello World")
// Output: INFO TEST_ONE test_two (test_three) Hello World foo:bar
```
### Sub dictionary ### Sub dictionary
```go ```go

View file

@ -1 +0,0 @@
remote_theme: rs/gh-readme

View file

@ -47,6 +47,10 @@ const (
// Formatter transforms the input into a formatted string. // Formatter transforms the input into a formatted string.
type Formatter func(interface{}) string type Formatter func(interface{}) string
// FormatterByFieldName transforms the input into a formatted string,
// being able to differentiate formatting based on field name.
type FormatterByFieldName func(interface{}, string) string
// ConsoleWriter parses the JSON input and writes it in an // ConsoleWriter parses the JSON input and writes it in an
// (optionally) colorized, human-friendly format to Out. // (optionally) colorized, human-friendly format to Out.
type ConsoleWriter struct { type ConsoleWriter struct {
@ -85,6 +89,9 @@ type ConsoleWriter struct {
FormatFieldValue Formatter FormatFieldValue Formatter
FormatErrFieldName Formatter FormatErrFieldName Formatter
FormatErrFieldValue Formatter FormatErrFieldValue Formatter
// If this is configured it is used for "part" values and
// has precedence on FormatFieldValue
FormatPartValueByName FormatterByFieldName
FormatExtra func(map[string]interface{}, *bytes.Buffer) error FormatExtra func(map[string]interface{}, *bytes.Buffer) error
@ -282,8 +289,9 @@ func (w ConsoleWriter) writeFields(evt map[string]interface{}, buf *bytes.Buffer
// writePart appends a formatted part to buf. // writePart appends a formatted part to buf.
func (w ConsoleWriter) writePart(buf *bytes.Buffer, evt map[string]interface{}, p string) { func (w ConsoleWriter) writePart(buf *bytes.Buffer, evt map[string]interface{}, p string) {
var f Formatter var f Formatter
var fvn FormatterByFieldName
if w.PartsExclude != nil && len(w.PartsExclude) > 0 { if len(w.PartsExclude) > 0 {
for _, exclude := range w.PartsExclude { for _, exclude := range w.PartsExclude {
if exclude == p { if exclude == p {
return return
@ -317,14 +325,21 @@ func (w ConsoleWriter) writePart(buf *bytes.Buffer, evt map[string]interface{},
f = w.FormatCaller f = w.FormatCaller
} }
default: default:
if w.FormatFieldValue == nil { if w.FormatPartValueByName != nil {
f = consoleDefaultFormatFieldValue fvn = w.FormatPartValueByName
} else { } else if w.FormatFieldValue != nil {
f = w.FormatFieldValue f = w.FormatFieldValue
} else {
f = consoleDefaultFormatFieldValue
} }
} }
var s = f(evt[p]) var s string
if f == nil {
s = fvn(evt[p], p)
} else {
s = f(evt[p])
}
if len(s) > 0 { if len(s) > 0 {
if buf.Len() > 0 { if buf.Len() > 0 {

View file

@ -494,7 +494,7 @@ func (l *Logger) newEvent(level Level, done func(string)) *Event {
if level != NoLevel && LevelFieldName != "" { if level != NoLevel && LevelFieldName != "" {
e.Str(LevelFieldName, LevelFieldMarshalFunc(level)) e.Str(LevelFieldName, LevelFieldMarshalFunc(level))
} }
if l.context != nil && len(l.context) > 1 { if len(l.context) > 1 {
e.buf = enc.AppendObjectData(e.buf, l.context) e.buf = enc.AppendObjectData(e.buf, l.context)
} }
if l.stack { if l.stack {

View file

@ -47,6 +47,9 @@ type BasicSampler struct {
// Sample implements the Sampler interface. // Sample implements the Sampler interface.
func (s *BasicSampler) Sample(lvl Level) bool { func (s *BasicSampler) Sample(lvl Level) bool {
n := s.N n := s.N
if n == 0 {
return false
}
if n == 1 { if n == 1 {
return true return true
} }
@ -87,7 +90,7 @@ func (s *BurstSampler) inc() uint32 {
now := TimestampFunc().UnixNano() now := TimestampFunc().UnixNano()
resetAt := atomic.LoadInt64(&s.resetAt) resetAt := atomic.LoadInt64(&s.resetAt)
var c uint32 var c uint32
if now > resetAt { if now >= resetAt {
c = 1 c = 1
atomic.StoreUint32(&s.counter, c) atomic.StoreUint32(&s.counter, c)
newResetAt := now + s.Period.Nanoseconds() newResetAt := now + s.Period.Nanoseconds()

View file

@ -213,6 +213,15 @@ func (w *FilteredLevelWriter) WriteLevel(level Level, p []byte) (int, error) {
return len(p), nil return len(p), nil
} }
// Call the underlying writer's Close method if it is an io.Closer. Otherwise
// does nothing.
func (w *FilteredLevelWriter) Close() error {
if closer, ok := w.Writer.(io.Closer); ok {
return closer.Close()
}
return nil
}
var triggerWriterPool = &sync.Pool{ var triggerWriterPool = &sync.Pool{
New: func() interface{} { New: func() interface{} {
return bytes.NewBuffer(make([]byte, 0, 1024)) return bytes.NewBuffer(make([]byte, 0, 1024))

2
vendor/modules.txt vendored
View file

@ -76,7 +76,7 @@ github.com/pkg/sftp/internal/encoding/ssh/filexfer
# github.com/pmezard/go-difflib v1.0.0 # github.com/pmezard/go-difflib v1.0.0
## explicit ## explicit
github.com/pmezard/go-difflib/difflib github.com/pmezard/go-difflib/difflib
# github.com/rs/zerolog v1.33.0 # github.com/rs/zerolog v1.34.0
## explicit; go 1.15 ## explicit; go 1.15
github.com/rs/zerolog github.com/rs/zerolog
github.com/rs/zerolog/internal/cbor github.com/rs/zerolog/internal/cbor