mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-09 19:45:58 +08:00
log
This commit is contained in:
+22
-28
@@ -2,15 +2,16 @@ package log
|
||||
|
||||
import (
|
||||
"OpenIM/pkg/common/config"
|
||||
"OpenIM/pkg/common/tracelog"
|
||||
"bufio"
|
||||
"context"
|
||||
|
||||
//"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
nested "github.com/antonfisher/nested-logrus-formatter"
|
||||
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
|
||||
"github.com/rifflock/lfshook"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -96,33 +97,26 @@ func loggerInit(moduleName string) *LogrusLogger {
|
||||
"",
|
||||
}
|
||||
}
|
||||
func NewLfsHook(rotationTime time.Duration, maxRemainNum uint, moduleName string) logrus.Hook {
|
||||
lfsHook := lfshook.NewHook(lfshook.WriterMap{
|
||||
logrus.DebugLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName),
|
||||
logrus.InfoLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName),
|
||||
logrus.WarnLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName),
|
||||
logrus.ErrorLevel: initRotateLogs(rotationTime, maxRemainNum, "all", moduleName),
|
||||
}, &nested.Formatter{
|
||||
TimestampFormat: "2006-01-02 15:04:05.000",
|
||||
HideKeys: false,
|
||||
FieldsOrder: []string{"PID", "FilePath", "OperationID"},
|
||||
})
|
||||
return lfsHook
|
||||
|
||||
func InfoKv(ctx context.Context, msg string, keysAndValues ...interface{}) {
|
||||
operationID := tracelog.GetOperationID(ctx)
|
||||
logger.WithFields(logrus.Fields{
|
||||
"OperationID": operationID,
|
||||
"PID": logger.Pid,
|
||||
"Msg": msg,
|
||||
}).Infoln(keysAndValues)
|
||||
}
|
||||
func initRotateLogs(rotationTime time.Duration, maxRemainNum uint, level string, moduleName string) *rotatelogs.RotateLogs {
|
||||
if moduleName != "" {
|
||||
moduleName = moduleName + "."
|
||||
}
|
||||
writer, err := rotatelogs.New(
|
||||
config.Config.Log.StorageLocation+moduleName+level+"."+"%Y-%m-%d",
|
||||
rotatelogs.WithRotationTime(rotationTime),
|
||||
rotatelogs.WithRotationCount(maxRemainNum),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
} else {
|
||||
return writer
|
||||
}
|
||||
|
||||
func DebugKv(ctx context.Context, msg string, keysAndValues ...interface{}) {
|
||||
|
||||
}
|
||||
|
||||
func ErrorKv(ctx context.Context, msg string, err error, keysAndValues ...interface{}) {
|
||||
|
||||
}
|
||||
|
||||
func WarnKv(ctx context.Context, msg string, err error, keysAndValues ...interface{}) {
|
||||
|
||||
}
|
||||
|
||||
func Info(OperationID string, args ...interface{}) {
|
||||
|
||||
Reference in New Issue
Block a user