Skip to content

Commit

Permalink
处理日志文件句柄泄漏 Close #309 (#349)
Browse files Browse the repository at this point in the history
* 处理日志文件句柄泄漏 Close #309

* add notes
  • Loading branch information
lbbniu authored Mar 23, 2022
1 parent e5320e7 commit a53ab89
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tars/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -62,13 +66,21 @@ 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
}

// 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
}
Expand Down

0 comments on commit a53ab89

Please sign in to comment.