From 5d0428059a6f0806cf1f2ef03e006ca08079d186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BE=B7=E6=BB=A1?= Date: Thu, 4 Mar 2021 23:18:51 +0800 Subject: [PATCH] =?UTF-8?q?logger=20=E5=BA=93NPE=E5=81=9A=E5=85=BC?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logger/logger.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/logger/logger.go b/logger/logger.go index 300382a..e30d90c 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -11,6 +11,8 @@ import ( "io" "os" + "github.com/pkg/errors" + "go.uber.org/zap" "go.uber.org/zap/zapcore" @@ -24,6 +26,12 @@ import ( // // Date : 5:05 下午 2021/1/2 func NewLogger(loggerLevel zapcore.Level, consoleOutput bool, encoder zapcore.Encoder, splitConfig *RotateLogConfig) (*zap.Logger, error) { + if nil == splitConfig { + return nil, errors.New("未配置日志切割规则") + } + if nil == encoder { + encoder = GetEncoder() + } loggerLevelDeal := zap.LevelEnablerFunc(func(lvl zapcore.Level) bool { return lvl >= loggerLevel })