mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-27 20:30:40 +08:00
log
This commit is contained in:
parent
e67dc28e82
commit
fd7b0da269
@ -22,7 +22,8 @@ var ctxLogger *Logger
|
|||||||
|
|
||||||
type Logger struct {
|
type Logger struct {
|
||||||
*logrus.Logger
|
*logrus.Logger
|
||||||
Pid int
|
Pid int
|
||||||
|
Type string
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -58,6 +59,7 @@ func ctxLoggerInit(moduleName string) *Logger {
|
|||||||
return &Logger{
|
return &Logger{
|
||||||
ctxLogger,
|
ctxLogger,
|
||||||
os.Getpid(),
|
os.Getpid(),
|
||||||
|
"ctxLogger",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +97,7 @@ func loggerInit(moduleName string) *Logger {
|
|||||||
return &Logger{
|
return &Logger{
|
||||||
logger,
|
logger,
|
||||||
os.Getpid(),
|
os.Getpid(),
|
||||||
|
"",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
func NewLfsHook(rotationTime time.Duration, maxRemainNum uint, moduleName string) logrus.Hook {
|
func NewLfsHook(rotationTime time.Duration, maxRemainNum uint, moduleName string) logrus.Hook {
|
||||||
@ -239,11 +242,13 @@ func ShowLog(ctx context.Context) {
|
|||||||
OperationID := trace_log.GetOperationID(ctx)
|
OperationID := trace_log.GetOperationID(ctx)
|
||||||
if ctx.Value(trace_log.TraceLogKey).(*trace_log.ApiInfo).GinCtx != nil {
|
if ctx.Value(trace_log.TraceLogKey).(*trace_log.ApiInfo).GinCtx != nil {
|
||||||
ctxLogger.WithFields(logrus.Fields{
|
ctxLogger.WithFields(logrus.Fields{
|
||||||
|
"Type": ctxLogger.Type,
|
||||||
"OperationID": OperationID,
|
"OperationID": OperationID,
|
||||||
"PID": ctxLogger.Pid,
|
"PID": ctxLogger.Pid,
|
||||||
}).Infoln("api: ", t.ApiName)
|
}).Infoln("api: ", t.ApiName)
|
||||||
} else {
|
} else {
|
||||||
ctxLogger.WithFields(logrus.Fields{
|
ctxLogger.WithFields(logrus.Fields{
|
||||||
|
"Type": ctxLogger.Type,
|
||||||
"OperationID": OperationID,
|
"OperationID": OperationID,
|
||||||
"PID": ctxLogger.Pid,
|
"PID": ctxLogger.Pid,
|
||||||
}).Infoln("rpc: ", t.ApiName)
|
}).Infoln("rpc: ", t.ApiName)
|
||||||
@ -251,6 +256,7 @@ func ShowLog(ctx context.Context) {
|
|||||||
for _, v := range *t.Funcs {
|
for _, v := range *t.Funcs {
|
||||||
if v.Err != nil {
|
if v.Err != nil {
|
||||||
ctxLogger.WithFields(logrus.Fields{
|
ctxLogger.WithFields(logrus.Fields{
|
||||||
|
"Type": ctxLogger.Type,
|
||||||
"OperationID": OperationID,
|
"OperationID": OperationID,
|
||||||
"PID": ctxLogger.Pid,
|
"PID": ctxLogger.Pid,
|
||||||
"FilePath": v.File,
|
"FilePath": v.File,
|
||||||
@ -259,18 +265,21 @@ func ShowLog(ctx context.Context) {
|
|||||||
switch v.LogLevel {
|
switch v.LogLevel {
|
||||||
case logrus.InfoLevel:
|
case logrus.InfoLevel:
|
||||||
ctxLogger.WithFields(logrus.Fields{
|
ctxLogger.WithFields(logrus.Fields{
|
||||||
|
"Type": ctxLogger.Type,
|
||||||
"OperationID": OperationID,
|
"OperationID": OperationID,
|
||||||
"PID": ctxLogger.Pid,
|
"PID": ctxLogger.Pid,
|
||||||
"FilePath": v.File,
|
"FilePath": v.File,
|
||||||
}).Infoln("func: ", v.FuncName, " args: ", v.Args)
|
}).Infoln("func: ", v.FuncName, " args: ", v.Args)
|
||||||
case logrus.DebugLevel:
|
case logrus.DebugLevel:
|
||||||
ctxLogger.WithFields(logrus.Fields{
|
ctxLogger.WithFields(logrus.Fields{
|
||||||
|
"Type": ctxLogger.Type,
|
||||||
"OperationID": OperationID,
|
"OperationID": OperationID,
|
||||||
"PID": ctxLogger.Pid,
|
"PID": ctxLogger.Pid,
|
||||||
"FilePath": v.File,
|
"FilePath": v.File,
|
||||||
}).Debugln("func: ", v.FuncName, " args: ", v.Args)
|
}).Debugln("func: ", v.FuncName, " args: ", v.Args)
|
||||||
case logrus.WarnLevel:
|
case logrus.WarnLevel:
|
||||||
ctxLogger.WithFields(logrus.Fields{
|
ctxLogger.WithFields(logrus.Fields{
|
||||||
|
"Type": ctxLogger.Type,
|
||||||
"OperationID": OperationID,
|
"OperationID": OperationID,
|
||||||
"PID": ctxLogger.Pid,
|
"PID": ctxLogger.Pid,
|
||||||
"FilePath": v.File,
|
"FilePath": v.File,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user