From 5becd73213011a6692572c0f0dfb7c90f1a7f006 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Tue, 12 Jan 2021 10:23:17 +0300 Subject: [PATCH] cleanup Signed-off-by: Vasiliy Tolstov --- zerolog.go | 9 +-------- zerolog_test.go | 17 ++++++++--------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/zerolog.go b/zerolog.go index 64cc32b..1209087 100644 --- a/zerolog.go +++ b/zerolog.go @@ -205,7 +205,6 @@ func (l *zeroLogger) String() string { } func (l *zeroLogger) Options() logger.Options { - // FIXME: How to return full opts? return l.opts.Options } @@ -213,12 +212,7 @@ func (l *zeroLogger) Options() logger.Options { func NewLogger(opts ...logger.Option) logger.Logger { // Default options options := Options{ - Options: logger.Options{ - Level: 100, - Fields: make(map[string]interface{}), - Out: os.Stderr, - Context: context.Background(), - }, + Options: logger.NewOptions(opts...), ReportCaller: false, UseAsDefault: false, Mode: Production, @@ -226,7 +220,6 @@ func NewLogger(opts ...logger.Option) logger.Logger { } l := &zeroLogger{opts: options} - _ = l.Init(opts...) return l } diff --git a/zerolog_test.go b/zerolog_test.go index f40a535..cee87ed 100644 --- a/zerolog_test.go +++ b/zerolog_test.go @@ -13,7 +13,7 @@ import ( func TestName(t *testing.T) { l := NewLogger() - + l.Init() if l.String() != "zerolog" { t.Errorf("error: name expected 'zerolog' actual: %s", l.String()) } @@ -23,13 +23,12 @@ func TestName(t *testing.T) { func TestWithOutput(t *testing.T) { logger.DefaultLogger = NewLogger(logger.WithOutput(os.Stdout)) - + logger.DefaultLogger.Init() logger.Infof(context.TODO(), "testing: %s", "WithOutput") } func TestSetLevel(t *testing.T) { logger.DefaultLogger = NewLogger() - logger.Init(logger.WithLevel(logger.DebugLevel)) logger.Debugf(context.TODO(), "test show debug: %s", "debug msg") @@ -39,25 +38,25 @@ func TestSetLevel(t *testing.T) { func TestWithReportCaller(t *testing.T) { logger.DefaultLogger = NewLogger(ReportCaller()) - + logger.DefaultLogger.Init() logger.Infof(context.TODO(), "testing: %s", "WithReportCaller") } func TestWithOut(t *testing.T) { logger.DefaultLogger = NewLogger(logger.WithOutput(os.Stdout)) - + logger.DefaultLogger.Init() logger.Infof(context.TODO(), "testing: %s", "WithOut") } func TestWithDevelopmentMode(t *testing.T) { logger.DefaultLogger = NewLogger(WithDevelopmentMode(), WithTimeFormat(time.Kitchen)) - + logger.DefaultLogger.Init() logger.Infof(context.TODO(), "testing: %s", "DevelopmentMode") } func TestWithFields(t *testing.T) { logger.DefaultLogger = NewLogger() - + logger.DefaultLogger.Init() logger.Fields(map[string]interface{}{ "sumo": "demo", "human": true, @@ -67,7 +66,7 @@ func TestWithFields(t *testing.T) { func TestWithError(t *testing.T) { logger.DefaultLogger = NewLogger() - + logger.DefaultLogger.Init() logger.Fields(map[string]interface{}{"error": errors.New("I am Error")}).Errorf(context.TODO(), "testing: %s", "WithError") } @@ -78,6 +77,6 @@ func TestWithHooks(t *testing.T) { }) logger.DefaultLogger = NewLogger(WithHooks([]zerolog.Hook{simpleHook})) - + logger.DefaultLogger.Init() logger.Infof(context.TODO(), "testing: %s", "WithHooks") }