From 09244e757fae144412832172d7cb7bbcc495fd0f Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 12 Jan 2023 16:06:21 +0800 Subject: [PATCH] log --- pkg/common/log/logrus.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/common/log/logrus.go b/pkg/common/log/logrus.go index 2c3c56fa1..0c8156edb 100644 --- a/pkg/common/log/logrus.go +++ b/pkg/common/log/logrus.go @@ -32,6 +32,7 @@ func init() { func NewPrivateLog(moduleName string) { logger = loggerInit(moduleName) + ctxLogger = loggerInit(moduleName) } func ctxLoggerInit(moduleName string) *Logger { @@ -43,13 +44,17 @@ func ctxLoggerInit(moduleName string) *Logger { } writer := bufio.NewWriter(src) ctxLogger.SetOutput(writer) - ctxLogger.SetFormatter(&logrus.JSONFormatter{ - TimestampFormat: "2006-01-02 15:04:05.000", - DataKey: "args", - FieldMap: nil, - CallerPrettyfier: nil, - PrettyPrint: false, + ctxLogger.SetFormatter(&nested.Formatter{ + TimestampFormat: "2006-01-02 15:04:05.000", + HideKeys: false, + FieldsOrder: []string{"PID", "FilePath", "OperationID"}, }) + if config.Config.Log.ElasticSearchSwitch { + ctxLogger.AddHook(newEsHook(moduleName)) + } + //Log file segmentation hook + hook := NewLfsHook(time.Duration(config.Config.Log.RotationTime)*time.Hour, config.Config.Log.RemainRotationCount, moduleName) + ctxLogger.AddHook(hook) return &Logger{ ctxLogger, os.Getpid(),