Skip to content

Commit

Permalink
Merge pull request #2 from adrienaury/fix/zerolog-1.28-compat
Browse files Browse the repository at this point in the history
fix zerolog v1.28.0 compatibility
  • Loading branch information
emrearslan committed Dec 26, 2022
2 parents 65a3da7 + e9bf97c commit c32e223
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 76 deletions.
122 changes: 61 additions & 61 deletions encoder.go
@@ -1,61 +1,61 @@
package over

import (
"github.com/rs/zerolog"
"strconv"
"strings"
)

func LowercaseLevelEncoder() func(l zerolog.Level) string {
return func(l zerolog.Level) string {
return l.String()
}
}

func UppercaseLevelEncoder() func(l zerolog.Level) string {
return func(l zerolog.Level) string {
switch l {
case zerolog.TraceLevel:
return "TRACE"
case zerolog.DebugLevel:
return "DEBUG"
case zerolog.InfoLevel:
return "INFO"
case zerolog.WarnLevel:
return "WARN"
case zerolog.ErrorLevel:
return "ERROR"
case zerolog.FatalLevel:
return "FATAL"
case zerolog.PanicLevel:
return "PANIC"
case zerolog.NoLevel:
return ""
}
return ""
}
}

func FullCallerEncoder() func(file string, line int) string {
return func(file string, line int) string {
return file + ":" + strconv.Itoa(line)
}
}

func ShortCallerEncoder() func(file string, line int) string {
return func(file string, line int) string {
return TrimmedPath(file) + ":" + strconv.Itoa(line)
}
}

func TrimmedPath(file string) string {
idx := strings.LastIndexByte(file, '/')
if idx == -1 {
return file
}
idx = strings.LastIndexByte(file[:idx], '/')
if idx == -1 {
return file
}
return file[idx+1:]
}
package over

import (
"github.com/rs/zerolog"
"strconv"
"strings"
)

func LowercaseLevelEncoder() func(l zerolog.Level) string {
return func(l zerolog.Level) string {
return l.String()
}
}

func UppercaseLevelEncoder() func(l zerolog.Level) string {
return func(l zerolog.Level) string {
switch l {
case zerolog.TraceLevel:
return "TRACE"
case zerolog.DebugLevel:
return "DEBUG"
case zerolog.InfoLevel:
return "INFO"
case zerolog.WarnLevel:
return "WARN"
case zerolog.ErrorLevel:
return "ERROR"
case zerolog.FatalLevel:
return "FATAL"
case zerolog.PanicLevel:
return "PANIC"
case zerolog.NoLevel:
return ""
}
return ""
}
}

func FullCallerEncoder() func(pc uintptr, file string, line int) string {
return func(pc uintptr, file string, line int) string {
return file + ":" + strconv.Itoa(line)
}
}

func ShortCallerEncoder() func(pc uintptr, file string, line int) string {
return func(pc uintptr, file string, line int) string {
return TrimmedPath(file) + ":" + strconv.Itoa(line)
}
}

func TrimmedPath(file string) string {
idx := strings.LastIndexByte(file, '/')
if idx == -1 {
return file
}
idx = strings.LastIndexByte(file[:idx], '/')
if idx == -1 {
return file
}
return file[idx+1:]
}
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -3,6 +3,6 @@ module github.com/Trendyol/overlog
go 1.14

require (
github.com/rs/zerolog v1.18.0
github.com/rs/zerolog v1.28.0
github.com/stretchr/testify v1.5.1
)
28 changes: 14 additions & 14 deletions go.sum
@@ -1,24 +1,24 @@
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
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=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
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/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ=
github.com/rs/zerolog v1.18.0 h1:CbAm3kP2Tptby1i9sYy2MGRg0uxIN9cyDb59Ys7W8z8=
github.com/rs/zerolog v1.18.0/go.mod h1:9nvC1axdVrAHcu/s9taAVfBuIdTZLVQmKQyvrUjF5+I=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY=
github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190828213141-aed303cbaa74/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 h1:foEbQz/B0Oz6YIqu/69kfXPYeFQAuuMYFkjaqXzl5Wo=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

0 comments on commit c32e223

Please sign in to comment.