Add adapters
This commit is contained in:
parent
ed50ff00ef
commit
be389eb931
15
adapters/logrus/go.mod
Normal file
15
adapters/logrus/go.mod
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
module go.arsenm.dev/logger/adapters/logrus
|
||||||
|
|
||||||
|
go 1.19
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/sirupsen/logrus v1.9.0
|
||||||
|
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/gookit/color v1.5.1 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||||
|
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
|
||||||
|
)
|
27
adapters/logrus/go.sum
Normal file
27
adapters/logrus/go.sum
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ=
|
||||||
|
github.com/gookit/color v1.5.1/go.mod h1:wZFzea4X8qN6vHOSP2apMb4/+w/orMznEzYsIHPaqKM=
|
||||||
|
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/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||||
|
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
|
||||||
|
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
||||||
|
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
|
||||||
|
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
|
||||||
|
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df h1:8mBHvEe7BJmpOeKSMA5YLqrGo9dCpePocTeR0C1+/2w=
|
||||||
|
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df/go.mod h1:RV2qydKDdoyaRkhAq8JEGvojR8eJ6bjq5WnSIlH7gYw=
|
||||||
|
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
|
||||||
|
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
244
adapters/logrus/logrus.go
Normal file
244
adapters/logrus/logrus.go
Normal file
@ -0,0 +1,244 @@
|
|||||||
|
package logrus
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
"go.arsenm.dev/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ logger.Logger = &LogrusLogger{}
|
||||||
|
var _ logger.LogBuilder = &LogrusLogBuilder{}
|
||||||
|
|
||||||
|
type LogrusLogger struct {
|
||||||
|
logger *logrus.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(l *logrus.Logger) *LogrusLogger {
|
||||||
|
return &LogrusLogger{l}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NoPanic is a no-op because logrus does not provide this functionality
|
||||||
|
func (ll *LogrusLogger) NoPanic() {}
|
||||||
|
|
||||||
|
// NoExit prevents the logger from exiting on fatal events
|
||||||
|
func (ll *LogrusLogger) NoExit() {
|
||||||
|
ll.logger.ExitFunc = func(int) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetLevel sets the log level of the logger
|
||||||
|
func (ll *LogrusLogger) SetLevel(logger.LogLevel) {}
|
||||||
|
|
||||||
|
// Debug creates a new debug event with the given message
|
||||||
|
func (ll *LogrusLogger) Debug(msg string) logger.LogBuilder {
|
||||||
|
return &LogrusLogBuilder{
|
||||||
|
log: logrus.NewEntry(ll.logger),
|
||||||
|
lvl: logrus.DebugLevel,
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debugf creates a new debug event with the formatted message
|
||||||
|
func (ll *LogrusLogger) Debugf(format string, v ...any) logger.LogBuilder {
|
||||||
|
return &LogrusLogBuilder{
|
||||||
|
log: logrus.NewEntry(ll.logger),
|
||||||
|
lvl: logrus.DebugLevel,
|
||||||
|
msg: fmt.Sprintf(format, v...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Info creates a new info event with the given message
|
||||||
|
func (ll *LogrusLogger) Info(msg string) logger.LogBuilder {
|
||||||
|
return &LogrusLogBuilder{
|
||||||
|
log: logrus.NewEntry(ll.logger),
|
||||||
|
lvl: logrus.InfoLevel,
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Infof creates a new info event with the formatted message
|
||||||
|
func (ll *LogrusLogger) Infof(format string, v ...any) logger.LogBuilder {
|
||||||
|
return &LogrusLogBuilder{
|
||||||
|
log: logrus.NewEntry(ll.logger),
|
||||||
|
lvl: logrus.InfoLevel,
|
||||||
|
msg: fmt.Sprintf(format, v...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warn creates a new warn event with the given message
|
||||||
|
func (ll *LogrusLogger) Warn(msg string) logger.LogBuilder {
|
||||||
|
return &LogrusLogBuilder{
|
||||||
|
log: logrus.NewEntry(ll.logger),
|
||||||
|
lvl: logrus.WarnLevel,
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warnf creates a new warn event with the formatted message
|
||||||
|
func (ll *LogrusLogger) Warnf(format string, v ...any) logger.LogBuilder {
|
||||||
|
return &LogrusLogBuilder{
|
||||||
|
log: logrus.NewEntry(ll.logger),
|
||||||
|
lvl: logrus.WarnLevel,
|
||||||
|
msg: fmt.Sprintf(format, v...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error creates a new error event with the given message
|
||||||
|
func (ll *LogrusLogger) Error(msg string) logger.LogBuilder {
|
||||||
|
return &LogrusLogBuilder{
|
||||||
|
log: logrus.NewEntry(ll.logger),
|
||||||
|
lvl: logrus.ErrorLevel,
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Errorf creates a new error event with the formatted message
|
||||||
|
func (ll *LogrusLogger) Errorf(format string, v ...any) logger.LogBuilder {
|
||||||
|
return &LogrusLogBuilder{
|
||||||
|
log: logrus.NewEntry(ll.logger),
|
||||||
|
lvl: logrus.ErrorLevel,
|
||||||
|
msg: fmt.Sprintf(format, v...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatal creates a new fatal event with the given message
|
||||||
|
func (ll *LogrusLogger) Fatal(msg string) logger.LogBuilder {
|
||||||
|
return &LogrusLogBuilder{
|
||||||
|
log: logrus.NewEntry(ll.logger),
|
||||||
|
lvl: logrus.FatalLevel,
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatalf creates a new fatal event with the formatted message
|
||||||
|
func (ll *LogrusLogger) Fatalf(format string, v ...any) logger.LogBuilder {
|
||||||
|
return &LogrusLogBuilder{
|
||||||
|
log: logrus.NewEntry(ll.logger),
|
||||||
|
lvl: logrus.FatalLevel,
|
||||||
|
msg: fmt.Sprintf(format, v...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Panic creates a new panic event with the given message
|
||||||
|
func (ll *LogrusLogger) Panic(msg string) logger.LogBuilder {
|
||||||
|
return &LogrusLogBuilder{
|
||||||
|
log: logrus.NewEntry(ll.logger),
|
||||||
|
lvl: logrus.PanicLevel,
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Panicf creates a new panic event with the formatted message
|
||||||
|
func (ll *LogrusLogger) Panicf(format string, v ...any) logger.LogBuilder {
|
||||||
|
return &LogrusLogBuilder{
|
||||||
|
log: logrus.NewEntry(ll.logger),
|
||||||
|
lvl: logrus.PanicLevel,
|
||||||
|
msg: fmt.Sprintf(format, v...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type LogrusLogBuilder struct {
|
||||||
|
log *logrus.Entry
|
||||||
|
lvl logrus.Level
|
||||||
|
msg string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Int(name string, value int) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithField(name, value)
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Int8(name string, value int8) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithField(name, value)
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Int16(name string, value int16) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithField(name, value)
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Int32(name string, value int32) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithField(name, value)
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Int64(name string, value int64) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithField(name, value)
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Uint(name string, value uint) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithField(name, value)
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Uint8(name string, value uint8) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithField(name, value)
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Uint16(name string, value uint16) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithField(name, value)
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Uint32(name string, value uint32) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithField(name, value)
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Uint64(name string, value uint64) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithField(name, value)
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Float32(name string, value float32) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithField(name, value)
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Float64(name string, value float64) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithField(name, value)
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Stringer(name string, value fmt.Stringer) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithField(name, value.String())
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Bytes(name string, value []byte) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithField(name, value)
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Timestamp() logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithTime(time.Now())
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Bool(name string, value bool) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithField(name, value)
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Str(name string, value string) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithField(name, value)
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Any(name string, value any) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithField(name, value)
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Err(value error) logger.LogBuilder {
|
||||||
|
lb.log = lb.log.WithError(value)
|
||||||
|
return lb
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lb *LogrusLogBuilder) Send() {
|
||||||
|
lb.log.Logln(lb.lvl, lb.msg)
|
||||||
|
}
|
17
adapters/zap/go.mod
Normal file
17
adapters/zap/go.mod
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
module go.arsenm.dev/logger/adapters/zap
|
||||||
|
|
||||||
|
go 1.18
|
||||||
|
|
||||||
|
require (
|
||||||
|
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df
|
||||||
|
go.uber.org/zap v1.24.0
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/gookit/color v1.5.1 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||||
|
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
||||||
|
go.uber.org/atomic v1.7.0 // indirect
|
||||||
|
go.uber.org/multierr v1.6.0 // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
|
||||||
|
)
|
32
adapters/zap/go.sum
Normal file
32
adapters/zap/go.sum
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ=
|
||||||
|
github.com/gookit/color v1.5.1/go.mod h1:wZFzea4X8qN6vHOSP2apMb4/+w/orMznEzYsIHPaqKM=
|
||||||
|
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.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||||
|
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
|
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
||||||
|
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||||
|
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
|
||||||
|
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
|
||||||
|
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df h1:8mBHvEe7BJmpOeKSMA5YLqrGo9dCpePocTeR0C1+/2w=
|
||||||
|
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df/go.mod h1:RV2qydKDdoyaRkhAq8JEGvojR8eJ6bjq5WnSIlH7gYw=
|
||||||
|
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
|
||||||
|
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||||
|
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
|
||||||
|
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
|
||||||
|
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
||||||
|
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
|
||||||
|
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
|
||||||
|
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
|
||||||
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
270
adapters/zap/zap.go
Normal file
270
adapters/zap/zap.go
Normal file
@ -0,0 +1,270 @@
|
|||||||
|
package adapters
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go.arsenm.dev/logger"
|
||||||
|
"go.uber.org/zap"
|
||||||
|
"go.uber.org/zap/zapcore"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ logger.Logger = &ZapLogger{}
|
||||||
|
var _ logger.LogBuilder = &ZapLogBuilder{}
|
||||||
|
|
||||||
|
type ZapLogger struct {
|
||||||
|
Logger *zap.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(z *zap.Logger) *ZapLogger {
|
||||||
|
return &ZapLogger{z.WithOptions(zap.AddCallerSkip(1))}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NoPanic is a no-op because Zap does not provide this functionality
|
||||||
|
func (zl *ZapLogger) NoPanic() {}
|
||||||
|
|
||||||
|
// NoExit is a no-op because Zap does not provide this functionality
|
||||||
|
func (zl *ZapLogger) NoExit() {}
|
||||||
|
|
||||||
|
// SetLevel sets the log level of the logger.
|
||||||
|
//
|
||||||
|
// Because zap only allows level increases, it can only increase
|
||||||
|
// the level. If the given level is lower than the current log level,
|
||||||
|
// SetLevel will be a no-op.
|
||||||
|
func (zl *ZapLogger) SetLevel(lvl logger.LogLevel) {
|
||||||
|
var zlvl zapcore.Level
|
||||||
|
switch lvl {
|
||||||
|
case logger.LogLevelDebug:
|
||||||
|
zlvl = zapcore.DebugLevel
|
||||||
|
case logger.LogLevelInfo:
|
||||||
|
zlvl = zapcore.InfoLevel
|
||||||
|
case logger.LogLevelWarn:
|
||||||
|
zlvl = zapcore.WarnLevel
|
||||||
|
case logger.LogLevelError:
|
||||||
|
zlvl = zapcore.WarnLevel
|
||||||
|
case logger.LogLevelFatal:
|
||||||
|
zlvl = zapcore.FatalLevel
|
||||||
|
case logger.LogLevelPanic:
|
||||||
|
zlvl = zapcore.PanicLevel
|
||||||
|
}
|
||||||
|
|
||||||
|
zl.Logger = zl.Logger.WithOptions(zap.IncreaseLevel(zlvl))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debug creates a new debug event with the given message
|
||||||
|
func (zl *ZapLogger) Debug(msg string) logger.LogBuilder {
|
||||||
|
return &ZapLogBuilder{
|
||||||
|
logger: zl.Logger,
|
||||||
|
lvl: zapcore.DebugLevel,
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Debugf creates a new debug event with the formatted message
|
||||||
|
func (zl *ZapLogger) Debugf(format string, v ...any) logger.LogBuilder {
|
||||||
|
return &ZapLogBuilder{
|
||||||
|
logger: zl.Logger,
|
||||||
|
lvl: zapcore.DebugLevel,
|
||||||
|
msg: fmt.Sprintf(format, v...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Info creates a new info event with the given message
|
||||||
|
func (zl *ZapLogger) Info(msg string) logger.LogBuilder {
|
||||||
|
return &ZapLogBuilder{
|
||||||
|
logger: zl.Logger,
|
||||||
|
lvl: zapcore.InfoLevel,
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Infof creates a new info event with the formatted message
|
||||||
|
func (zl *ZapLogger) Infof(format string, v ...any) logger.LogBuilder {
|
||||||
|
return &ZapLogBuilder{
|
||||||
|
logger: zl.Logger,
|
||||||
|
lvl: zapcore.InfoLevel,
|
||||||
|
msg: fmt.Sprintf(format, v...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warn creates a new warn event with the given message
|
||||||
|
func (zl *ZapLogger) Warn(msg string) logger.LogBuilder {
|
||||||
|
return &ZapLogBuilder{
|
||||||
|
logger: zl.Logger,
|
||||||
|
lvl: zapcore.WarnLevel,
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warnf creates a new warn event with the formatted message
|
||||||
|
func (zl *ZapLogger) Warnf(format string, v ...any) logger.LogBuilder {
|
||||||
|
return &ZapLogBuilder{
|
||||||
|
logger: zl.Logger,
|
||||||
|
lvl: zapcore.WarnLevel,
|
||||||
|
msg: fmt.Sprintf(format, v...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Error creates a new error event with the given message
|
||||||
|
func (zl *ZapLogger) Error(msg string) logger.LogBuilder {
|
||||||
|
return &ZapLogBuilder{
|
||||||
|
logger: zl.Logger,
|
||||||
|
lvl: zapcore.ErrorLevel,
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Errorf creates a new error event with the formatted message
|
||||||
|
func (zl *ZapLogger) Errorf(format string, v ...any) logger.LogBuilder {
|
||||||
|
return &ZapLogBuilder{
|
||||||
|
logger: zl.Logger,
|
||||||
|
lvl: zapcore.ErrorLevel,
|
||||||
|
msg: fmt.Sprintf(format, v...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatal creates a new fatal event with the given message
|
||||||
|
func (zl *ZapLogger) Fatal(msg string) logger.LogBuilder {
|
||||||
|
return &ZapLogBuilder{
|
||||||
|
logger: zl.Logger,
|
||||||
|
lvl: zapcore.FatalLevel,
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatalf creates a new fatal event with the formatted message
|
||||||
|
func (zl *ZapLogger) Fatalf(format string, v ...any) logger.LogBuilder {
|
||||||
|
return &ZapLogBuilder{
|
||||||
|
logger: zl.Logger,
|
||||||
|
lvl: zapcore.FatalLevel,
|
||||||
|
msg: fmt.Sprintf(format, v...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Panic creates a new panic event with the given message
|
||||||
|
func (zl *ZapLogger) Panic(msg string) logger.LogBuilder {
|
||||||
|
return &ZapLogBuilder{
|
||||||
|
logger: zl.Logger,
|
||||||
|
lvl: zapcore.PanicLevel,
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Panicf creates a new panic event with the formatted message
|
||||||
|
func (zl *ZapLogger) Panicf(format string, v ...any) logger.LogBuilder {
|
||||||
|
return &ZapLogBuilder{
|
||||||
|
logger: zl.Logger,
|
||||||
|
lvl: zapcore.PanicLevel,
|
||||||
|
msg: fmt.Sprintf(format, v...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type ZapLogBuilder struct {
|
||||||
|
logger *zap.Logger
|
||||||
|
lvl zapcore.Level
|
||||||
|
msg string
|
||||||
|
fields []zap.Field
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewZapLogBuilder(logger *zap.Logger) logger.LogBuilder {
|
||||||
|
return &ZapLogBuilder{logger: logger}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Int(key string, value int) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Int(key, value))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Int8(key string, value int8) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Int8(key, value))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Int16(key string, value int16) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Int16(key, value))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Int32(key string, value int32) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Int32(key, value))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Int64(key string, value int64) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Int64(key, value))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Uint(key string, value uint) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Uint(key, value))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Uint8(key string, value uint8) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Uint8(key, value))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Uint16(key string, value uint16) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Uint16(key, value))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Uint32(key string, value uint32) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Uint32(key, value))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Uint64(key string, value uint64) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Uint64(key, value))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Float32(key string, value float32) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Float32(key, value))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Float64(key string, value float64) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Float64(key, value))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Stringer(key string, value fmt.Stringer) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Stringer(key, value))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Bytes(key string, value []byte) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Binary(key, value))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Timestamp() logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Time("timestamp", time.Now()))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Bool(key string, value bool) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Bool(key, value))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Str(key string, value string) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.String(key, value))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Any(key string, value any) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Any(key, value))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Err(err error) logger.LogBuilder {
|
||||||
|
b.fields = append(b.fields, zap.Error(err))
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZapLogBuilder) Send() {
|
||||||
|
b.logger.Log(b.lvl, b.msg, b.fields...)
|
||||||
|
}
|
16
adapters/zerolog/go.mod
Normal file
16
adapters/zerolog/go.mod
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
module go.arsenm.dev/logger/adapters/zerolog
|
||||||
|
|
||||||
|
go 1.18
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/rs/zerolog v1.28.0
|
||||||
|
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df
|
||||||
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/gookit/color v1.5.1 // indirect
|
||||||
|
github.com/mattn/go-colorable v0.1.12 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.14 // indirect
|
||||||
|
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 // indirect
|
||||||
|
)
|
30
adapters/zerolog/go.sum
Normal file
30
adapters/zerolog/go.sum
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
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/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
|
github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ=
|
||||||
|
github.com/gookit/color v1.5.1/go.mod h1:wZFzea4X8qN6vHOSP2apMb4/+w/orMznEzYsIHPaqKM=
|
||||||
|
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.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.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
|
||||||
|
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
||||||
|
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
|
||||||
|
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
|
||||||
|
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df h1:8mBHvEe7BJmpOeKSMA5YLqrGo9dCpePocTeR0C1+/2w=
|
||||||
|
go.arsenm.dev/logger v0.0.0-20230104225304-d706171ea6df/go.mod h1:RV2qydKDdoyaRkhAq8JEGvojR8eJ6bjq5WnSIlH7gYw=
|
||||||
|
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
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/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
232
adapters/zerolog/zerolog.go
Normal file
232
adapters/zerolog/zerolog.go
Normal file
@ -0,0 +1,232 @@
|
|||||||
|
package zerolog
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog"
|
||||||
|
"go.arsenm.dev/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ logger.Logger = &ZerologLogger{}
|
||||||
|
var _ logger.LogBuilder = &ZerologLogBuilder{}
|
||||||
|
|
||||||
|
type ZerologLogger struct {
|
||||||
|
logger zerolog.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(z zerolog.Logger) *ZerologLogger {
|
||||||
|
return &ZerologLogger{z}
|
||||||
|
}
|
||||||
|
|
||||||
|
// NoPanic is a no-op because Zerolog does not provide this functionality
|
||||||
|
func (l *ZerologLogger) NoPanic() {}
|
||||||
|
|
||||||
|
// NoPanic is a no-op because Zerolog does not provide this functionality
|
||||||
|
func (l *ZerologLogger) NoExit() {}
|
||||||
|
|
||||||
|
// SetLevel sets the log level of the logger.
|
||||||
|
func (l *ZerologLogger) SetLevel(level logger.LogLevel) {
|
||||||
|
switch level {
|
||||||
|
case logger.LogLevelDebug:
|
||||||
|
l.logger = l.logger.Level(zerolog.DebugLevel)
|
||||||
|
case logger.LogLevelInfo:
|
||||||
|
l.logger = l.logger.Level(zerolog.InfoLevel)
|
||||||
|
case logger.LogLevelWarn:
|
||||||
|
l.logger = l.logger.Level(zerolog.WarnLevel)
|
||||||
|
case logger.LogLevelError:
|
||||||
|
l.logger = l.logger.Level(zerolog.ErrorLevel)
|
||||||
|
case logger.LogLevelFatal:
|
||||||
|
l.logger = l.logger.Level(zerolog.FatalLevel)
|
||||||
|
case logger.LogLevelPanic:
|
||||||
|
l.logger = l.logger.Level(zerolog.PanicLevel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ZerologLogger) Debug(msg string) logger.LogBuilder {
|
||||||
|
return &ZerologLogBuilder{
|
||||||
|
logEvent: l.logger.Debug(),
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ZerologLogger) Debugf(format string, a ...any) logger.LogBuilder {
|
||||||
|
return &ZerologLogBuilder{
|
||||||
|
logEvent: l.logger.Debug(),
|
||||||
|
msg: fmt.Sprintf(format, a...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ZerologLogger) Info(msg string) logger.LogBuilder {
|
||||||
|
return &ZerologLogBuilder{
|
||||||
|
logEvent: l.logger.Info(),
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ZerologLogger) Infof(format string, a ...any) logger.LogBuilder {
|
||||||
|
return &ZerologLogBuilder{
|
||||||
|
logEvent: l.logger.Info(),
|
||||||
|
msg: fmt.Sprintf(format, a...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ZerologLogger) Warn(msg string) logger.LogBuilder {
|
||||||
|
return &ZerologLogBuilder{
|
||||||
|
logEvent: l.logger.Warn(),
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ZerologLogger) Warnf(format string, a ...any) logger.LogBuilder {
|
||||||
|
return &ZerologLogBuilder{
|
||||||
|
logEvent: l.logger.Warn(),
|
||||||
|
msg: fmt.Sprintf(format, a...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ZerologLogger) Error(msg string) logger.LogBuilder {
|
||||||
|
return &ZerologLogBuilder{
|
||||||
|
logEvent: l.logger.Error(),
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ZerologLogger) Errorf(format string, a ...any) logger.LogBuilder {
|
||||||
|
return &ZerologLogBuilder{
|
||||||
|
logEvent: l.logger.Error(),
|
||||||
|
msg: fmt.Sprintf(format, a...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ZerologLogger) Fatal(msg string) logger.LogBuilder {
|
||||||
|
return &ZerologLogBuilder{
|
||||||
|
logEvent: l.logger.Fatal(),
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ZerologLogger) Fatalf(format string, a ...any) logger.LogBuilder {
|
||||||
|
return &ZerologLogBuilder{
|
||||||
|
logEvent: l.logger.Fatal(),
|
||||||
|
msg: fmt.Sprintf(format, a...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ZerologLogger) Panic(msg string) logger.LogBuilder {
|
||||||
|
return &ZerologLogBuilder{
|
||||||
|
logEvent: l.logger.Panic(),
|
||||||
|
msg: msg,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *ZerologLogger) Panicf(format string, a ...any) logger.LogBuilder {
|
||||||
|
return &ZerologLogBuilder{
|
||||||
|
logEvent: l.logger.Panic(),
|
||||||
|
msg: fmt.Sprintf(format, a...),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type ZerologLogBuilder struct {
|
||||||
|
logEvent *zerolog.Event
|
||||||
|
msg string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Int(key string, value int) logger.LogBuilder {
|
||||||
|
b.logEvent.Int(key, value)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Int8(key string, value int8) logger.LogBuilder {
|
||||||
|
b.logEvent.Int8(key, value)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Int16(key string, value int16) logger.LogBuilder {
|
||||||
|
b.logEvent.Int16(key, value)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Int32(key string, value int32) logger.LogBuilder {
|
||||||
|
b.logEvent.Int32(key, value)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Int64(key string, value int64) logger.LogBuilder {
|
||||||
|
b.logEvent.Int64(key, value)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Uint(key string, value uint) logger.LogBuilder {
|
||||||
|
b.logEvent.Uint(key, value)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Uint8(key string, value uint8) logger.LogBuilder {
|
||||||
|
b.logEvent.Uint8(key, value)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Uint16(key string, value uint16) logger.LogBuilder {
|
||||||
|
b.logEvent.Uint16(key, value)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Uint32(key string, value uint32) logger.LogBuilder {
|
||||||
|
b.logEvent.Uint32(key, value)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Uint64(key string, value uint64) logger.LogBuilder {
|
||||||
|
b.logEvent.Uint64(key, value)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Float32(key string, value float32) logger.LogBuilder {
|
||||||
|
b.logEvent.Float32(key, value)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Float64(key string, value float64) logger.LogBuilder {
|
||||||
|
b.logEvent.Float64(key, value)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Stringer(key string, value fmt.Stringer) logger.LogBuilder {
|
||||||
|
b.logEvent.Str(key, value.String())
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Bytes(key string, value []byte) logger.LogBuilder {
|
||||||
|
b.logEvent.Bytes(key, value)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Timestamp() logger.LogBuilder {
|
||||||
|
b.logEvent.Time("timestamp", time.Now())
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Bool(key string, value bool) logger.LogBuilder {
|
||||||
|
b.logEvent.Bool(key, value)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Str(key string, value string) logger.LogBuilder {
|
||||||
|
b.logEvent.Str(key, value)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Any(key string, value any) logger.LogBuilder {
|
||||||
|
b.logEvent.Interface(key, value)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Err(err error) logger.LogBuilder {
|
||||||
|
b.logEvent.Err(err)
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ZerologLogBuilder) Send() {
|
||||||
|
b.logEvent.Msg(b.msg)
|
||||||
|
}
|
3
go.mod
3
go.mod
@ -8,6 +8,7 @@ require (
|
|||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/stretchr/testify v1.8.0 // indirect
|
||||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
|
||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
|
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 // indirect
|
||||||
)
|
)
|
||||||
|
12
go.sum
12
go.sum
@ -1,5 +1,6 @@
|
|||||||
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/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ=
|
github.com/gookit/color v1.5.1 h1:Vjg2VEcdHpwq+oY63s/ksHrgJYCTo0bwWvmmYWdE9fQ=
|
||||||
github.com/gookit/color v1.5.1/go.mod h1:wZFzea4X8qN6vHOSP2apMb4/+w/orMznEzYsIHPaqKM=
|
github.com/gookit/color v1.5.1/go.mod h1:wZFzea4X8qN6vHOSP2apMb4/+w/orMznEzYsIHPaqKM=
|
||||||
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
|
||||||
@ -7,13 +8,18 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
|
|||||||
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
||||||
|
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
|
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 h1:QldyIu/L63oPpyvQmHgvgickp1Yw510KJOqX7H24mg8=
|
||||||
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
|
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778/go.mod h1:2MuV+tbUrU1zIOPMxZ5EncGwgmMJsa+9ucAQZXxsObs=
|
||||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
|
|
||||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
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/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
8
go.work
Normal file
8
go.work
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
go 1.19
|
||||||
|
|
||||||
|
use (
|
||||||
|
.
|
||||||
|
./adapters/zap
|
||||||
|
./adapters/zerolog
|
||||||
|
./adapters/logrus
|
||||||
|
)
|
1
go.work.sum
Normal file
1
go.work.sum
Normal file
@ -0,0 +1 @@
|
|||||||
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
10
log/log.go
10
log/log.go
@ -72,3 +72,13 @@ func Fatal(msg string) logger.LogBuilder {
|
|||||||
func Fatalf(format string, v ...any) logger.LogBuilder {
|
func Fatalf(format string, v ...any) logger.LogBuilder {
|
||||||
return Logger.Fatalf(format, v...)
|
return Logger.Fatalf(format, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fatal creates a new fatal event with the given message
|
||||||
|
func Panic(msg string) logger.LogBuilder {
|
||||||
|
return Logger.Panic(msg)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fatalf creates a new fatal event with the formatted message
|
||||||
|
func Panicf(format string, v ...any) logger.LogBuilder {
|
||||||
|
return Logger.Panicf(format, v...)
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user