From 551da36ac984bdd35c7a21f674c60a49e18f6141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E5=BE=B7=E6=BB=A1?= Date: Sat, 17 Apr 2021 23:18:58 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=BB=98=E8=AE=A4=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E6=96=87=E4=BB=B6=E8=B7=AF=E5=BE=84=E4=B8=8E=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/server.go | 4 ++++ construct.go | 3 +++ 2 files changed, 7 insertions(+) diff --git a/config/server.go b/config/server.go index b3113e5..1d1b917 100644 --- a/config/server.go +++ b/config/server.go @@ -80,6 +80,10 @@ func SetWSServerLogEnable(logPath string, logFile string, logLevel zapcore.Level // 传入非法值,默认按小时切割日志 splitInterval = DefaultLogSplitInterval } + if len(logPath) == 0 { + logPath = "./logs" + } + wsc.LogEnable = true wsc.LogPath = logPath wsc.LogFile = logFile diff --git a/construct.go b/construct.go index 0afeb07..96fd43a 100644 --- a/construct.go +++ b/construct.go @@ -100,6 +100,9 @@ func NewWebsocketServe(wsInstanceList ...abstract.IWebsocket) error { if s.conf.LogConsole { optionList = append(optionList, logger.WithConsoleOutput()) } + if len(s.conf.LogFile) == 0 { + s.conf.LogFile = wsInstance.GetModuleFlag() + ".log" + } if logConf, err = logger.NewRotateLogConfig(s.conf.LogPath, s.conf.LogFile, logger.WithTimeIntervalType(s.conf.LogSplitInterval)); nil != err { panic(wsInstance.GetModuleFlag() + " 模块开启了日志记录,日志初始化失败, 失败原因 : " + err.Error()) }