From a53ab890e9b6c211369d84cc01e02b0edac288c8 Mon Sep 17 00:00:00 2001 From: lbbniu Date: Wed, 23 Mar 2022 15:55:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E6=97=A5=E5=BF=97=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=8F=A5=E6=9F=84=E6=B3=84=E6=BC=8F=20Close=20#309=20?= =?UTF-8?q?(#349)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 处理日志文件句柄泄漏 Close #309 * add notes --- tars/logger.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tars/logger.go b/tars/logger.go index 1d688d4f..75127db0 100644 --- a/tars/logger.go +++ b/tars/logger.go @@ -37,6 +37,10 @@ func Trace(traceKey, annotation, client, server, funcName string, ret int, data, // GetLogger Get a logger func GetLogger(name string) *rogger.Logger { logPath, cfg, lg := getLogger(name) + // if the default writer is not ConsoleWriter, the writer has already been configured + if !lg.IsConsoleWriter() { + return lg + } if cfg == nil { return lg } @@ -62,6 +66,10 @@ func getLogger(name string) (logPath string, cfg *serverConfig, lg *rogger.Logge // GetDayLogger Get a logger roll by day func GetDayLogger(name string, numDay int) *rogger.Logger { logPath, _, lg := getLogger(name) + // if the default writer is not ConsoleWriter, the writer has already been configured + if !lg.IsConsoleWriter() { + return lg + } lg.SetDayRoller(logPath, numDay) return lg } @@ -69,6 +77,10 @@ func GetDayLogger(name string, numDay int) *rogger.Logger { // GetHourLogger Get a logger roll by hour func GetHourLogger(name string, numHour int) *rogger.Logger { logPath, _, lg := getLogger(name) + // if the default writer is not ConsoleWriter, the writer has already been configured + if !lg.IsConsoleWriter() { + return lg + } lg.SetHourRoller(logPath, numHour) return lg }