From d3cb3ba728338801921bd2ed1ff5334ef40e9c8a Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 9 Nov 2017 15:09:40 +0900 Subject: [PATCH] ing --- logging.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/logging.go b/logging.go index d2f8c64..b9f392a 100644 --- a/logging.go +++ b/logging.go @@ -6,9 +6,16 @@ import ( "go.uber.org/zap" ) -var Logger *zap.Logger +var logger *zap.Logger -func init() { +func Logger() *zap.Logger { + if nil != logger { + initializeLogger() + } + return logger +} + +func initializeLogger() { var cfg zap.Config var err error @@ -16,10 +23,13 @@ func init() { conf.SetConfigPath("./config") if err = conf.Load(&cfg, "logging.json"); nil != err { - panic(err) + if logger, err = zap.NewDevelopment(); nil != err { + panic(err) + } + return } - if Logger, err = cfg.Build(); nil != err { + if logger, err = cfg.Build(); nil != err { panic(err) } }