loggers updated to match to interface (#480)
refactor loggers to match go-micro changes
This commit is contained in:
parent
cf98ce105a
commit
bf669d8b9e
58
options.go
58
options.go
@ -1,82 +1,66 @@
|
|||||||
package zerolog
|
package zerolog
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"github.com/rs/zerolog"
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/micro/go-micro/v2/logger"
|
"github.com/micro/go-micro/v2/logger"
|
||||||
"github.com/rs/zerolog"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
logger.Options
|
logger.Options
|
||||||
|
|
||||||
|
// Flag for whether to log caller info (off by default)
|
||||||
|
ReportCaller bool
|
||||||
|
// Use this logger as system wide default logger (off by default)
|
||||||
|
UseAsDefault bool
|
||||||
|
// zerolog hooks
|
||||||
|
Hooks []zerolog.Hook
|
||||||
|
// TimeFormat is one of time.RFC3339, time.RFC3339Nano, time.*
|
||||||
|
TimeFormat string
|
||||||
|
// Runtime mode. (Production by default)
|
||||||
|
Mode Mode
|
||||||
|
// Exit Function to call when FatalLevel log
|
||||||
|
ExitFunc func(int)
|
||||||
}
|
}
|
||||||
|
|
||||||
type reportCallerKey struct{}
|
type reportCallerKey struct{}
|
||||||
|
|
||||||
func ReportCaller() logger.Option {
|
func ReportCaller() logger.Option {
|
||||||
return setOption(reportCallerKey{}, true)
|
return logger.SetOption(reportCallerKey{}, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
type useAsDefaultKey struct{}
|
type useAsDefaultKey struct{}
|
||||||
|
|
||||||
func UseAsDefault() logger.Option {
|
func UseAsDefault() logger.Option {
|
||||||
return setOption(useAsDefaultKey{}, true)
|
return logger.SetOption(useAsDefaultKey{}, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
type developmentModeKey struct{}
|
type developmentModeKey struct{}
|
||||||
|
|
||||||
func WithDevelopmentMode() logger.Option {
|
func WithDevelopmentMode() logger.Option {
|
||||||
return setOption(developmentModeKey{}, true)
|
return logger.SetOption(developmentModeKey{}, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
type productionModeKey struct{}
|
type productionModeKey struct{}
|
||||||
|
|
||||||
func WithProductionMode() logger.Option {
|
func WithProductionMode() logger.Option {
|
||||||
return setOption(productionModeKey{}, true)
|
return logger.SetOption(productionModeKey{}, true)
|
||||||
}
|
|
||||||
|
|
||||||
type outKey struct{}
|
|
||||||
|
|
||||||
func WithOut(out io.Writer) logger.Option {
|
|
||||||
return setOption(outKey{}, out)
|
|
||||||
}
|
|
||||||
|
|
||||||
type fieldsKey struct{}
|
|
||||||
|
|
||||||
func WithFields(fields map[string]interface{}) logger.Option {
|
|
||||||
return setOption(fieldsKey{}, fields)
|
|
||||||
}
|
|
||||||
|
|
||||||
type levelKey struct{}
|
|
||||||
|
|
||||||
func WithLevel(lvl logger.Level) logger.Option {
|
|
||||||
return setOption(levelKey{}, lvl)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type timeFormatKey struct{}
|
type timeFormatKey struct{}
|
||||||
|
|
||||||
func WithTimeFormat(timeFormat string) logger.Option {
|
func WithTimeFormat(timeFormat string) logger.Option {
|
||||||
return setOption(timeFormatKey{}, timeFormat)
|
return logger.SetOption(timeFormatKey{}, timeFormat)
|
||||||
}
|
}
|
||||||
|
|
||||||
type hooksKey struct{}
|
type hooksKey struct{}
|
||||||
|
|
||||||
func WithHooks(hooks []zerolog.Hook) logger.Option {
|
func WithHooks(hooks []zerolog.Hook) logger.Option {
|
||||||
return setOption(hooksKey{}, hooks)
|
return logger.SetOption(hooksKey{}, hooks)
|
||||||
}
|
}
|
||||||
|
|
||||||
type exitKey struct{}
|
type exitKey struct{}
|
||||||
|
|
||||||
func WithExitFunc(exit func(int)) logger.Option {
|
func WithExitFunc(exit func(int)) logger.Option {
|
||||||
return setOption(exitKey{}, exit)
|
return logger.SetOption(exitKey{}, exit)
|
||||||
}
|
|
||||||
|
|
||||||
func setOption(k, v interface{}) logger.Option {
|
|
||||||
return func(o *logger.Options) {
|
|
||||||
if o.Context == nil {
|
|
||||||
o.Context = context.Background()
|
|
||||||
}
|
|
||||||
o.Context = context.WithValue(o.Context, k, v)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
183
zerolog.go
183
zerolog.go
@ -3,95 +3,61 @@ package zerolog
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/micro/go-micro/v2/logger"
|
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
zlog "github.com/rs/zerolog/log"
|
zlog "github.com/rs/zerolog/log"
|
||||||
"github.com/rs/zerolog/pkgerrors"
|
"github.com/rs/zerolog/pkgerrors"
|
||||||
|
|
||||||
|
"github.com/micro/go-micro/v2/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Mode uint8
|
type Mode uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Production Mode = iota + 1
|
Production Mode = iota
|
||||||
Development
|
Development
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// It's common to set this to a file, or leave it default which is `os.Stderr`
|
|
||||||
out io.Writer = os.Stderr
|
|
||||||
// Function to exit the application, defaults to `os.Exit()`
|
|
||||||
exitFunc = os.Exit
|
|
||||||
// Flag for whether to log caller info (off by default)
|
|
||||||
reportCaller = false
|
|
||||||
// use this logger as system wide default logger
|
|
||||||
useAsDefault = false
|
|
||||||
// The logging level the logger should log at.
|
|
||||||
// This defaults to 100 means not explicitly set by user
|
|
||||||
level logger.Level = 100
|
|
||||||
fields map[string]interface{}
|
|
||||||
hooks []zerolog.Hook
|
|
||||||
timeFormat string
|
|
||||||
// default Production (1)
|
|
||||||
mode Mode = Production
|
|
||||||
)
|
|
||||||
|
|
||||||
type zeroLogger struct {
|
type zeroLogger struct {
|
||||||
nativelogger zerolog.Logger
|
zLog zerolog.Logger
|
||||||
}
|
opts Options
|
||||||
|
|
||||||
func (l *zeroLogger) Fields(fields map[string]interface{}) logger.Logger {
|
|
||||||
return &zeroLogger{l.nativelogger.With().Fields(fields).Logger()}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (l *zeroLogger) Error(err error) logger.Logger {
|
|
||||||
return &zeroLogger{
|
|
||||||
l.nativelogger.With().Fields(map[string]interface{}{zerolog.ErrorFieldName: err}).Logger(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *zeroLogger) Init(opts ...logger.Option) error {
|
func (l *zeroLogger) Init(opts ...logger.Option) error {
|
||||||
|
|
||||||
options := &Options{logger.Options{Context: context.Background()}}
|
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&options.Options)
|
o(&l.opts.Options)
|
||||||
}
|
}
|
||||||
|
|
||||||
if o, ok := options.Context.Value(outKey{}).(io.Writer); ok {
|
if hs, ok := l.opts.Context.Value(hooksKey{}).([]zerolog.Hook); ok {
|
||||||
out = o
|
l.opts.Hooks = hs
|
||||||
}
|
}
|
||||||
if hs, ok := options.Context.Value(hooksKey{}).([]zerolog.Hook); ok {
|
if tf, ok := l.opts.Context.Value(timeFormatKey{}).(string); ok {
|
||||||
hooks = hs
|
l.opts.TimeFormat = tf
|
||||||
}
|
}
|
||||||
if flds, ok := options.Context.Value(fieldsKey{}).(map[string]interface{}); ok {
|
if exitFunction, ok := l.opts.Context.Value(exitKey{}).(func(int)); ok {
|
||||||
fields = flds
|
l.opts.ExitFunc = exitFunction
|
||||||
}
|
}
|
||||||
if lvl, ok := options.Context.Value(levelKey{}).(logger.Level); ok {
|
if caller, ok := l.opts.Context.Value(reportCallerKey{}).(bool); ok && caller {
|
||||||
level = lvl
|
l.opts.ReportCaller = caller
|
||||||
}
|
}
|
||||||
if tf, ok := options.Context.Value(timeFormatKey{}).(string); ok {
|
if useDefault, ok := l.opts.Context.Value(useAsDefaultKey{}).(bool); ok && useDefault {
|
||||||
timeFormat = tf
|
l.opts.UseAsDefault = useDefault
|
||||||
}
|
}
|
||||||
if exitFunction, ok := options.Context.Value(exitKey{}).(func(int)); ok {
|
if devMode, ok := l.opts.Context.Value(developmentModeKey{}).(bool); ok && devMode {
|
||||||
exitFunc = exitFunction
|
l.opts.Mode = Development
|
||||||
}
|
}
|
||||||
if caller, ok := options.Context.Value(reportCallerKey{}).(bool); ok && caller {
|
if prodMode, ok := l.opts.Context.Value(productionModeKey{}).(bool); ok && prodMode {
|
||||||
reportCaller = caller
|
l.opts.Mode = Production
|
||||||
}
|
|
||||||
if useDefault, ok := options.Context.Value(useAsDefaultKey{}).(bool); ok && useDefault {
|
|
||||||
useAsDefault = useDefault
|
|
||||||
}
|
|
||||||
if devMode, ok := options.Context.Value(developmentModeKey{}).(bool); ok && devMode {
|
|
||||||
mode = Development
|
|
||||||
}
|
|
||||||
if prodMode, ok := options.Context.Value(productionModeKey{}).(bool); ok && prodMode {
|
|
||||||
mode = Production
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch mode {
|
// RESET
|
||||||
|
zerolog.TimeFieldFormat = time.RFC3339
|
||||||
|
zerolog.ErrorStackMarshaler = nil
|
||||||
|
|
||||||
|
switch l.opts.Mode {
|
||||||
case Development:
|
case Development:
|
||||||
zerolog.ErrorStackMarshaler = func(err error) interface{} {
|
zerolog.ErrorStackMarshaler = func(err error) interface{} {
|
||||||
fmt.Println(string(debug.Stack()))
|
fmt.Println(string(debug.Stack()))
|
||||||
@ -99,84 +65,80 @@ func (l *zeroLogger) Init(opts ...logger.Option) error {
|
|||||||
}
|
}
|
||||||
consOut := zerolog.NewConsoleWriter(
|
consOut := zerolog.NewConsoleWriter(
|
||||||
func(w *zerolog.ConsoleWriter) {
|
func(w *zerolog.ConsoleWriter) {
|
||||||
if len(timeFormat) > 0 {
|
if len(l.opts.TimeFormat) > 0 {
|
||||||
w.TimeFormat = timeFormat
|
w.TimeFormat = l.opts.TimeFormat
|
||||||
}
|
}
|
||||||
w.Out = out
|
w.Out = l.opts.Out
|
||||||
w.NoColor = false
|
w.NoColor = false
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
level = logger.DebugLevel
|
//level = logger.DebugLevel
|
||||||
l.nativelogger = zerolog.New(consOut).
|
l.zLog = zerolog.New(consOut).
|
||||||
Level(zerolog.DebugLevel).
|
Level(zerolog.DebugLevel).
|
||||||
With().Timestamp().Stack().Logger()
|
With().Timestamp().Stack().Logger()
|
||||||
default: // Production
|
default: // Production
|
||||||
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
|
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack
|
||||||
l.nativelogger = zerolog.New(out).
|
l.zLog = zerolog.New(l.opts.Out).
|
||||||
Level(zerolog.InfoLevel).
|
Level(zerolog.InfoLevel).
|
||||||
With().Timestamp().Stack().Logger()
|
With().Timestamp().Stack().Logger()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change Writer if not default
|
|
||||||
if out != os.Stderr {
|
|
||||||
l.nativelogger = l.nativelogger.Output(out)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set log Level if not default
|
// Set log Level if not default
|
||||||
if level != 100 {
|
if l.opts.Level != 100 {
|
||||||
//zerolog.SetGlobalLevel(loggerToZerologLevel(level))
|
zerolog.SetGlobalLevel(loggerToZerologLevel(l.opts.Level))
|
||||||
l.nativelogger = l.nativelogger.Level(loggerToZerologLevel(level))
|
l.zLog = l.zLog.Level(loggerToZerologLevel(l.opts.Level))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adding hooks if exist
|
// Adding hooks if exist
|
||||||
if reportCaller {
|
if l.opts.ReportCaller {
|
||||||
l.nativelogger = l.nativelogger.With().Caller().Logger()
|
l.zLog = l.zLog.With().Caller().Logger()
|
||||||
}
|
}
|
||||||
for _, hook := range hooks {
|
for _, hook := range l.opts.Hooks {
|
||||||
l.nativelogger = l.nativelogger.Hook(hook)
|
l.zLog = l.zLog.Hook(hook)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setting timeFormat
|
// Setting timeFormat
|
||||||
if len(timeFormat) > 0 {
|
if len(l.opts.TimeFormat) > 0 {
|
||||||
zerolog.TimeFieldFormat = timeFormat
|
zerolog.TimeFieldFormat = l.opts.TimeFormat
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adding seed fields if exist
|
// Adding seed fields if exist
|
||||||
if fields != nil {
|
if l.opts.Fields != nil {
|
||||||
l.nativelogger = l.nativelogger.With().Fields(fields).Logger()
|
l.zLog = l.zLog.With().Fields(l.opts.Fields).Logger()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Also set it as zerolog's Default logger
|
// Also set it as zerolog's Default logger
|
||||||
if useAsDefault {
|
if l.opts.UseAsDefault {
|
||||||
zlog.Logger = l.nativelogger
|
zlog.Logger = l.zLog
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *zeroLogger) SetLevel(level logger.Level) {
|
func (l *zeroLogger) Fields(fields map[string]interface{}) logger.Logger {
|
||||||
//zerolog.SetGlobalLevel(loggerToZerologLevel(level))
|
l.zLog = l.zLog.With().Fields(fields).Logger()
|
||||||
l.nativelogger = l.nativelogger.Level(loggerToZerologLevel(level))
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *zeroLogger) Level() logger.Level {
|
func (l *zeroLogger) Error(err error) logger.Logger {
|
||||||
return ZerologToLoggerLevel(l.nativelogger.GetLevel())
|
l.zLog = l.zLog.With().Fields(map[string]interface{}{zerolog.ErrorFieldName: err}).Logger()
|
||||||
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *zeroLogger) Log(level logger.Level, args ...interface{}) {
|
func (l *zeroLogger) Log(level logger.Level, args ...interface{}) {
|
||||||
msg := fmt.Sprintf("%s", args)
|
msg := fmt.Sprint(args...)
|
||||||
l.nativelogger.WithLevel(loggerToZerologLevel(level)).Msg(msg[1 : len(msg)-1])
|
l.zLog.WithLevel(loggerToZerologLevel(level)).Msg(msg)
|
||||||
// Invoke os.Exit because unlike zerolog.Logger.Fatal zerolog.Logger.WithLevel won't stop the execution.
|
// Invoke os.Exit because unlike zerolog.Logger.Fatal zerolog.Logger.WithLevel won't stop the execution.
|
||||||
if level == logger.FatalLevel {
|
if level == logger.FatalLevel {
|
||||||
exitFunc(1)
|
l.opts.ExitFunc(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *zeroLogger) Logf(level logger.Level, format string, args ...interface{}) {
|
func (l *zeroLogger) Logf(level logger.Level, format string, args ...interface{}) {
|
||||||
l.nativelogger.WithLevel(loggerToZerologLevel(level)).Msgf(format, args...)
|
l.zLog.WithLevel(loggerToZerologLevel(level)).Msgf(format, args...)
|
||||||
// Invoke os.Exit because unlike zerolog.Logger.Fatal zerolog.Logger.WithLevel won't stop the execution.
|
// Invoke os.Exit because unlike zerolog.Logger.Fatal zerolog.Logger.WithLevel won't stop the execution.
|
||||||
if level == logger.FatalLevel {
|
if level == logger.FatalLevel {
|
||||||
exitFunc(1)
|
l.opts.ExitFunc(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,21 +146,30 @@ func (l *zeroLogger) String() string {
|
|||||||
return "zerolog"
|
return "zerolog"
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLogger builds a new logger based on options
|
func (l *zeroLogger) Options() logger.Options {
|
||||||
func NewLogger(opts ...logger.Option) logger.Logger {
|
// FIXME: How to return full opts?
|
||||||
l := &zeroLogger{}
|
return l.opts.Options
|
||||||
_ = l.Init(opts...)
|
|
||||||
return l
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseLevel converts a level string into a logger Level value.
|
// NewLogger builds a new logger based on options
|
||||||
// returns an error if the input string does not match known values.
|
func NewLogger(opts ...logger.Option) logger.Logger {
|
||||||
func ParseLevel(levelStr string) (lvl logger.Level, err error) {
|
// Default options
|
||||||
if zLevel, err := zerolog.ParseLevel(levelStr); err == nil {
|
options := Options{
|
||||||
return ZerologToLoggerLevel(zLevel), err
|
Options: logger.Options{
|
||||||
} else {
|
Level: 100,
|
||||||
return lvl, fmt.Errorf("Unknown Level String: '%s' %w", levelStr, err)
|
Fields: make(map[string]interface{}),
|
||||||
|
Out: os.Stderr,
|
||||||
|
Context: context.Background(),
|
||||||
|
},
|
||||||
|
ReportCaller: false,
|
||||||
|
UseAsDefault: false,
|
||||||
|
Mode: Production,
|
||||||
|
ExitFunc: os.Exit,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
l := &zeroLogger{opts: options}
|
||||||
|
_ = l.Init(opts...)
|
||||||
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
func loggerToZerologLevel(level logger.Level) zerolog.Level {
|
func loggerToZerologLevel(level logger.Level) zerolog.Level {
|
||||||
|
@ -20,47 +20,44 @@ func TestName(t *testing.T) {
|
|||||||
t.Logf("testing logger name: %s", l.String())
|
t.Logf("testing logger name: %s", l.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// func ExampleWithOut() {
|
func TestWithOutput(t *testing.T) {
|
||||||
// l := NewLogger(WithOut(os.Stdout), WithProductionMode())
|
logger.DefaultLogger = NewLogger(logger.WithOutput(os.Stdout))
|
||||||
|
|
||||||
// l.Logf(logger.InfoLevel, "testing: %s", "logf")
|
logger.Logf(logger.InfoLevel, "testing: %s", "WithOutput")
|
||||||
|
}
|
||||||
// // Output:
|
|
||||||
// // {"level":"info","time":"2020-02-14T22:15:36-08:00","message":"testing: logf"}
|
|
||||||
// }
|
|
||||||
|
|
||||||
func TestSetLevel(t *testing.T) {
|
func TestSetLevel(t *testing.T) {
|
||||||
l := NewLogger()
|
logger.DefaultLogger = NewLogger()
|
||||||
|
|
||||||
l.SetLevel(logger.DebugLevel)
|
logger.Init(logger.WithLevel(logger.DebugLevel))
|
||||||
l.Logf(logger.DebugLevel, "test show debug: %s", "debug msg")
|
logger.Logf(logger.DebugLevel, "test show debug: %s", "debug msg")
|
||||||
|
|
||||||
l.SetLevel(logger.InfoLevel)
|
logger.Init(logger.WithLevel(logger.InfoLevel))
|
||||||
l.Logf(logger.DebugLevel, "test non-show debug: %s", "debug msg")
|
logger.Logf(logger.DebugLevel, "test non-show debug: %s", "debug msg")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWithReportCaller(t *testing.T) {
|
func TestWithReportCaller(t *testing.T) {
|
||||||
l := NewLogger(ReportCaller())
|
logger.DefaultLogger = NewLogger(ReportCaller())
|
||||||
|
|
||||||
l.Logf(logger.InfoLevel, "testing: %s", "WithReportCaller")
|
logger.Logf(logger.InfoLevel, "testing: %s", "WithReportCaller")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWithOut(t *testing.T) {
|
func TestWithOut(t *testing.T) {
|
||||||
l := NewLogger(WithOut(os.Stdout))
|
logger.DefaultLogger = NewLogger(logger.WithOutput(os.Stdout))
|
||||||
|
|
||||||
l.Logf(logger.InfoLevel, "testing: %s", "WithOut")
|
logger.Logf(logger.InfoLevel, "testing: %s", "WithOut")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWithDevelopmentMode(t *testing.T) {
|
func TestWithDevelopmentMode(t *testing.T) {
|
||||||
l := NewLogger(WithDevelopmentMode(), WithTimeFormat(time.Kitchen))
|
logger.DefaultLogger = NewLogger(WithDevelopmentMode(), WithTimeFormat(time.Kitchen))
|
||||||
|
|
||||||
l.Logf(logger.InfoLevel, "testing: %s", "DevelopmentMode")
|
logger.Logf(logger.InfoLevel, "testing: %s", "DevelopmentMode")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWithFields(t *testing.T) {
|
func TestWithFields(t *testing.T) {
|
||||||
l := NewLogger()
|
logger.DefaultLogger = NewLogger()
|
||||||
|
|
||||||
l.Fields(map[string]interface{}{
|
logger.Fields(map[string]interface{}{
|
||||||
"sumo": "demo",
|
"sumo": "demo",
|
||||||
"human": true,
|
"human": true,
|
||||||
"age": 99,
|
"age": 99,
|
||||||
@ -68,9 +65,9 @@ func TestWithFields(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWithError(t *testing.T) {
|
func TestWithError(t *testing.T) {
|
||||||
l := NewLogger()
|
logger.DefaultLogger = NewLogger()
|
||||||
|
|
||||||
l.Error(errors.New("I am Error")).Logf(logger.ErrorLevel, "testing: %s", "WithError")
|
logger.WithError(errors.New("I am Error")).Logf(logger.ErrorLevel, "testing: %s", "WithError")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWithHooks(t *testing.T) {
|
func TestWithHooks(t *testing.T) {
|
||||||
@ -79,7 +76,7 @@ func TestWithHooks(t *testing.T) {
|
|||||||
e.Str("test", "logged")
|
e.Str("test", "logged")
|
||||||
})
|
})
|
||||||
|
|
||||||
l := NewLogger(WithHooks([]zerolog.Hook{simpleHook}))
|
logger.DefaultLogger = NewLogger(WithHooks([]zerolog.Hook{simpleHook}))
|
||||||
|
|
||||||
l.Logf(logger.InfoLevel, "testing: %s", "WithHooks")
|
logger.Logf(logger.InfoLevel, "testing: %s", "WithHooks")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user