From d3e8fb0415a929a5507a7d990ed6f76ccf7c23c8 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 15 Aug 2023 07:51:31 +0300 Subject: [PATCH] update for latest micro changes Signed-off-by: Vasiliy Tolstov --- go.mod | 10 +++++----- go.sum | 15 +++++++++++++++ options.go | 33 +++++++++++++++++---------------- zerolog.go | 7 ++++--- 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/go.mod b/go.mod index 9bba72e..467e41d 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,13 @@ module go.unistack.org/micro-logger-zerolog/v4 go 1.20 require ( - github.com/rs/zerolog v1.29.0 - go.unistack.org/micro/v4 v4.0.1 + github.com/rs/zerolog v1.30.0 + go.unistack.org/micro/v4 v4.0.6 ) require ( - github.com/mattn/go-colorable v0.1.12 // indirect - github.com/mattn/go-isatty v0.0.14 // indirect + github.com/mattn/go-colorable v0.1.13 // indirect + github.com/mattn/go-isatty v0.0.19 // indirect github.com/pkg/errors v0.9.1 // indirect - golang.org/x/sys v0.8.0 // indirect + golang.org/x/sys v0.11.0 // indirect ) diff --git a/go.sum b/go.sum index 223af28..1c4b0b2 100644 --- a/go.sum +++ b/go.sum @@ -1,18 +1,33 @@ github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= +github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= +github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= 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/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= +github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= +github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.29.0 h1:Zes4hju04hjbvkVkOhdl2HpZa+0PmVwigmo8XoORE5w= github.com/rs/zerolog v1.29.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0= +github.com/rs/zerolog v1.30.0 h1:SymVODrcRsaRaSInD9yQtKbtWqwsfoPcRff/oRXLj4c= +github.com/rs/zerolog v1.30.0/go.mod h1:/tk+P47gFdPXq4QYjvCmT5/Gsug2nagsFWBWhAiSi1w= go.unistack.org/micro/v4 v4.0.1 h1:xo1IxbVfgh8i0eY0VeYa3cbb13u5n/Mxnp3FOgWD4Jo= go.unistack.org/micro/v4 v4.0.1/go.mod h1:p/J5UcSJjfHsWGT31uKoghQ5rUQZzQJBAFy+Z4+ZVMs= +go.unistack.org/micro/v4 v4.0.6 h1:YFWvTh3VwyOd6NHYTQcf47n2TF5+p/EhpnbuBQX3qhk= +go.unistack.org/micro/v4 v4.0.6/go.mod h1:bVEYTlPi0EsdgZZt311bIroDg9ict7ky3C87dSCCAGk= 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= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/options.go b/options.go index 2abe95f..9d10607 100644 --- a/options.go +++ b/options.go @@ -4,6 +4,7 @@ import ( "github.com/rs/zerolog" "go.unistack.org/micro/v4/logger" + "go.unistack.org/micro/v4/options" ) type Options struct { @@ -25,48 +26,48 @@ type Options struct { type reportCallerKey struct{} -func ReportCaller() logger.Option { - return logger.SetOption(reportCallerKey{}, true) +func ReportCaller() options.Option { + return options.ContextOption(reportCallerKey{}, true) } type useAsDefaultKey struct{} -func UseAsDefault() logger.Option { - return logger.SetOption(useAsDefaultKey{}, true) +func UseAsDefault() options.Option { + return options.ContextOption(useAsDefaultKey{}, true) } type developmentModeKey struct{} -func WithDevelopmentMode() logger.Option { - return logger.SetOption(developmentModeKey{}, true) +func WithDevelopmentMode() options.Option { + return options.ContextOption(developmentModeKey{}, true) } type productionModeKey struct{} -func WithProductionMode() logger.Option { - return logger.SetOption(productionModeKey{}, true) +func WithProductionMode() options.Option { + return options.ContextOption(productionModeKey{}, true) } type timeFormatKey struct{} -func WithTimeFormat(timeFormat string) logger.Option { - return logger.SetOption(timeFormatKey{}, timeFormat) +func WithTimeFormat(timeFormat string) options.Option { + return options.ContextOption(timeFormatKey{}, timeFormat) } type hooksKey struct{} -func WithHooks(hooks []zerolog.Hook) logger.Option { - return logger.SetOption(hooksKey{}, hooks) +func WithHooks(hooks []zerolog.Hook) options.Option { + return options.ContextOption(hooksKey{}, hooks) } type exitKey struct{} -func WithExitFunc(exit func(int)) logger.Option { - return logger.SetOption(exitKey{}, exit) +func WithExitFunc(exit func(int)) options.Option { + return options.ContextOption(exitKey{}, exit) } type loggerKey struct{} -func WithLogger(l logger.Logger) logger.Option { - return logger.SetOption(loggerKey{}, l) +func WithLogger(l logger.Logger) options.Option { + return options.ContextOption(loggerKey{}, l) } diff --git a/zerolog.go b/zerolog.go index 8dd87b8..e10206e 100644 --- a/zerolog.go +++ b/zerolog.go @@ -11,6 +11,7 @@ import ( zlog "github.com/rs/zerolog/log" "github.com/rs/zerolog/pkgerrors" "go.unistack.org/micro/v4/logger" + "go.unistack.org/micro/v4/options" ) type Mode uint8 @@ -28,7 +29,7 @@ type zeroLogger struct { func (l *zeroLogger) Level(lvl logger.Level) { } -func (l *zeroLogger) Clone(opts ...logger.Option) logger.Logger { +func (l *zeroLogger) Clone(opts ...options.Option) logger.Logger { nl := &zeroLogger{zLog: l.zLog, opts: l.opts} for _, o := range opts { o(&nl.opts.Options) @@ -38,7 +39,7 @@ func (l *zeroLogger) Clone(opts ...logger.Option) logger.Logger { return nl } -func (l *zeroLogger) Init(opts ...logger.Option) error { +func (l *zeroLogger) Init(opts ...options.Option) error { for _, o := range opts { o(&l.opts.Options) } @@ -229,7 +230,7 @@ func (l *zeroLogger) Options() logger.Options { } // NewLogger builds a new logger based on options -func NewLogger(opts ...logger.Option) logger.Logger { +func NewLogger(opts ...options.Option) logger.Logger { // Default options options := Options{ Options: logger.NewOptions(opts...),