fix: 修改日志时间

This commit is contained in:
zhengkunwang223 2022-12-27 17:29:37 +08:00 committed by zhengkunwang223
parent 68ffcdd9de
commit 2aa0d839b3

View file

@ -53,16 +53,15 @@ func setOutput(logger *logrus.Logger, config configs.LogConfig) {
type MineFormatter struct{} type MineFormatter struct{}
func (s *MineFormatter) Format(entry *logrus.Entry) ([]byte, error) { func (s *MineFormatter) Format(entry *logrus.Entry) ([]byte, error) {
var cstSh, _ = time.LoadLocation(global.CONF.LogConfig.TimeZone)
detailInfo := "" detailInfo := ""
if entry.Caller != nil { if entry.Caller != nil {
funcion := strings.ReplaceAll(entry.Caller.Function, "github.com/1Panel-dev/1Panel/backend/", "") funcion := strings.ReplaceAll(entry.Caller.Function, "github.com/1Panel-dev/1Panel/backend/", "")
detailInfo = fmt.Sprintf("(%s: %d)", funcion, entry.Caller.Line) detailInfo = fmt.Sprintf("(%s: %d)", funcion, entry.Caller.Line)
} }
if len(entry.Data) == 0 { if len(entry.Data) == 0 {
msg := fmt.Sprintf("[%s] [%s] %s %s \n", time.Now().In(cstSh).Format(TimeFormat), strings.ToUpper(entry.Level.String()), entry.Message, detailInfo) msg := fmt.Sprintf("[%s] [%s] %s %s \n", time.Now().Format(TimeFormat), strings.ToUpper(entry.Level.String()), entry.Message, detailInfo)
return []byte(msg), nil return []byte(msg), nil
} }
msg := fmt.Sprintf("[%s] [%s] %s %s {%v} \n", time.Now().In(cstSh).Format(TimeFormat), strings.ToUpper(entry.Level.String()), entry.Message, detailInfo, entry.Data) msg := fmt.Sprintf("[%s] [%s] %s %s {%v} \n", time.Now().Format(TimeFormat), strings.ToUpper(entry.Level.String()), entry.Message, detailInfo, entry.Data)
return []byte(msg), nil return []byte(msg), nil
} }