mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-24 18:36:19 +08:00
log
This commit is contained in:
parent
04068d25cb
commit
9709271ae3
@ -24,7 +24,6 @@ mysql:
|
|||||||
|
|
||||||
mongo:
|
mongo:
|
||||||
dbUri: ""#当dbUri值不为空则直接使用该值
|
dbUri: ""#当dbUri值不为空则直接使用该值
|
||||||
#dbAddress: 127.0.0.1:37017 #单机时为mongo地址,使用分片集群时,为mongos地址 默认即可
|
|
||||||
dbAddress: [ 127.0.0.1:37017 ] #单机时为mongo地址,使用分片集群时,为mongos地址 默认即可
|
dbAddress: [ 127.0.0.1:37017 ] #单机时为mongo地址,使用分片集群时,为mongos地址 默认即可
|
||||||
dbDirect: false
|
dbDirect: false
|
||||||
dbTimeout: 60
|
dbTimeout: 60
|
||||||
@ -161,6 +160,8 @@ log:
|
|||||||
remainRotationCount: 2 #日志数量
|
remainRotationCount: 2 #日志数量
|
||||||
#日志级别 6表示全都打印,测试阶段建议设置为6
|
#日志级别 6表示全都打印,测试阶段建议设置为6
|
||||||
remainLogLevel: 6
|
remainLogLevel: 6
|
||||||
|
stderr: false
|
||||||
|
|
||||||
elasticSearchSwitch: false
|
elasticSearchSwitch: false
|
||||||
elasticSearchAddr: [ 127.0.0.1:9201 ]
|
elasticSearchAddr: [ 127.0.0.1:9201 ]
|
||||||
elasticSearchUser: ""
|
elasticSearchUser: ""
|
||||||
|
@ -182,6 +182,7 @@ type config struct {
|
|||||||
RotationTime int `yaml:"rotationTime"`
|
RotationTime int `yaml:"rotationTime"`
|
||||||
RemainRotationCount uint `yaml:"remainRotationCount"`
|
RemainRotationCount uint `yaml:"remainRotationCount"`
|
||||||
RemainLogLevel uint `yaml:"remainLogLevel"`
|
RemainLogLevel uint `yaml:"remainLogLevel"`
|
||||||
|
Stderr bool `yaml:"stderr"`
|
||||||
ElasticSearchSwitch bool `yaml:"elasticSearchSwitch"`
|
ElasticSearchSwitch bool `yaml:"elasticSearchSwitch"`
|
||||||
ElasticSearchAddr []string `yaml:"elasticSearchAddr"`
|
ElasticSearchAddr []string `yaml:"elasticSearchAddr"`
|
||||||
ElasticSearchUser string `yaml:"elasticSearchUser"`
|
ElasticSearchUser string `yaml:"elasticSearchUser"`
|
||||||
|
@ -1 +1,88 @@
|
|||||||
package log
|
package log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"OpenIM/pkg/common/tracelog"
|
||||||
|
"context"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
func ShowLog(ctx context.Context) {
|
||||||
|
t := ctx.Value(tracelog.TraceLogKey).(*tracelog.FuncInfos)
|
||||||
|
OperationID := tracelog.GetOperationID(ctx)
|
||||||
|
for _, v := range *t.Funcs {
|
||||||
|
if v.Err != nil {
|
||||||
|
ctxLogger.WithFields(logrus.Fields{
|
||||||
|
"OperationID": OperationID,
|
||||||
|
"PID": ctxLogger.Pid,
|
||||||
|
"FilePath": v.File,
|
||||||
|
}).Errorln("func: ", v.FuncName, " args: ", v.Args, v.Err.Error())
|
||||||
|
} else {
|
||||||
|
switch v.LogLevel {
|
||||||
|
case logrus.InfoLevel:
|
||||||
|
ctxLogger.WithFields(logrus.Fields{
|
||||||
|
"OperationID": OperationID,
|
||||||
|
"PID": ctxLogger.Pid,
|
||||||
|
"FilePath": v.File,
|
||||||
|
}).Infoln("func: ", v.FuncName, " args: ", v.Args)
|
||||||
|
case logrus.DebugLevel:
|
||||||
|
ctxLogger.WithFields(logrus.Fields{
|
||||||
|
"OperationID": OperationID,
|
||||||
|
"PID": ctxLogger.Pid,
|
||||||
|
"FilePath": v.File,
|
||||||
|
}).Debugln("func: ", v.FuncName, " args: ", v.Args)
|
||||||
|
case logrus.WarnLevel:
|
||||||
|
ctxLogger.WithFields(logrus.Fields{
|
||||||
|
"OperationID": OperationID,
|
||||||
|
"PID": ctxLogger.Pid,
|
||||||
|
"FilePath": v.File,
|
||||||
|
}).Warnln("func: ", v.FuncName, " args: ", v.Args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func InfoWithCtx(ctx context.Context, args ...interface{}) {
|
||||||
|
t := ctx.Value(tracelog.TraceLogKey).(*tracelog.FuncInfos)
|
||||||
|
OperationID := tracelog.GetOperationID(ctx)
|
||||||
|
for _, v := range *t.Funcs {
|
||||||
|
logger.WithFields(logrus.Fields{
|
||||||
|
"OperationID": OperationID,
|
||||||
|
"PID": logger.Pid,
|
||||||
|
}).Infoln(v.Args, args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func DebugWithCtx(ctx context.Context, args ...interface{}) {
|
||||||
|
t := ctx.Value(tracelog.TraceLogKey).(*tracelog.FuncInfos)
|
||||||
|
OperationID := tracelog.GetOperationID(ctx)
|
||||||
|
for _, v := range *t.Funcs {
|
||||||
|
logger.WithFields(logrus.Fields{
|
||||||
|
"OperationID": OperationID,
|
||||||
|
"PID": logger.Pid,
|
||||||
|
}).Debugln(v.Args, args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ErrorWithCtx(ctx context.Context, args ...interface{}) {
|
||||||
|
t := ctx.Value(tracelog.TraceLogKey).(*tracelog.FuncInfos)
|
||||||
|
OperationID := tracelog.GetOperationID(ctx)
|
||||||
|
for _, v := range *t.Funcs {
|
||||||
|
if v.Err != nil {
|
||||||
|
logger.WithFields(logrus.Fields{
|
||||||
|
"OperationID": OperationID,
|
||||||
|
"PID": logger.Pid,
|
||||||
|
}).Errorln(v.Err, v.Args, args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WarnWithCtx(ctx context.Context, args ...interface{}) {
|
||||||
|
t := ctx.Value(tracelog.TraceLogKey).(*tracelog.FuncInfos)
|
||||||
|
OperationID := tracelog.GetOperationID(ctx)
|
||||||
|
for _, v := range *t.Funcs {
|
||||||
|
logger.WithFields(logrus.Fields{
|
||||||
|
"OperationID": OperationID,
|
||||||
|
"PID": logger.Pid,
|
||||||
|
}).Warnln(v.Args, args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -2,9 +2,7 @@ package log
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"OpenIM/pkg/common/config"
|
"OpenIM/pkg/common/config"
|
||||||
"OpenIM/pkg/common/tracelog"
|
|
||||||
"bufio"
|
"bufio"
|
||||||
"context"
|
|
||||||
//"bufio"
|
//"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@ -16,8 +14,8 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger Logger = *LogrusLogger
|
var logger *LogrusLogger
|
||||||
var ctxLogger Logger = *LogrusLogger
|
var ctxLogger *LogrusLogger
|
||||||
|
|
||||||
type LogrusLogger struct {
|
type LogrusLogger struct {
|
||||||
*logrus.Logger
|
*logrus.Logger
|
||||||
@ -193,84 +191,3 @@ func NewWarn(OperationID string, args ...interface{}) {
|
|||||||
"PID": logger.Pid,
|
"PID": logger.Pid,
|
||||||
}).Warnln(args)
|
}).Warnln(args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShowLog(ctx context.Context) {
|
|
||||||
t := ctx.Value(tracelog.TraceLogKey).(*tracelog.FuncInfos)
|
|
||||||
OperationID := tracelog.GetOperationID(ctx)
|
|
||||||
for _, v := range *t.Funcs {
|
|
||||||
if v.Err != nil {
|
|
||||||
ctxLogger.WithFields(logrus.Fields{
|
|
||||||
"OperationID": OperationID,
|
|
||||||
"PID": ctxLogger.Pid,
|
|
||||||
"FilePath": v.File,
|
|
||||||
}).Errorln("func: ", v.FuncName, " args: ", v.Args, v.Err.Error())
|
|
||||||
} else {
|
|
||||||
switch v.LogLevel {
|
|
||||||
case logrus.InfoLevel:
|
|
||||||
ctxLogger.WithFields(logrus.Fields{
|
|
||||||
"OperationID": OperationID,
|
|
||||||
"PID": ctxLogger.Pid,
|
|
||||||
"FilePath": v.File,
|
|
||||||
}).Infoln("func: ", v.FuncName, " args: ", v.Args)
|
|
||||||
case logrus.DebugLevel:
|
|
||||||
ctxLogger.WithFields(logrus.Fields{
|
|
||||||
"OperationID": OperationID,
|
|
||||||
"PID": ctxLogger.Pid,
|
|
||||||
"FilePath": v.File,
|
|
||||||
}).Debugln("func: ", v.FuncName, " args: ", v.Args)
|
|
||||||
case logrus.WarnLevel:
|
|
||||||
ctxLogger.WithFields(logrus.Fields{
|
|
||||||
"OperationID": OperationID,
|
|
||||||
"PID": ctxLogger.Pid,
|
|
||||||
"FilePath": v.File,
|
|
||||||
}).Warnln("func: ", v.FuncName, " args: ", v.Args)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func InfoWithCtx(ctx context.Context, args ...interface{}) {
|
|
||||||
t := ctx.Value(tracelog.TraceLogKey).(*tracelog.FuncInfos)
|
|
||||||
OperationID := tracelog.GetOperationID(ctx)
|
|
||||||
for _, v := range *t.Funcs {
|
|
||||||
logger.WithFields(logrus.Fields{
|
|
||||||
"OperationID": OperationID,
|
|
||||||
"PID": logger.Pid,
|
|
||||||
}).Infoln(v.Args, args)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func DebugWithCtx(ctx context.Context, args ...interface{}) {
|
|
||||||
t := ctx.Value(tracelog.TraceLogKey).(*tracelog.FuncInfos)
|
|
||||||
OperationID := tracelog.GetOperationID(ctx)
|
|
||||||
for _, v := range *t.Funcs {
|
|
||||||
logger.WithFields(logrus.Fields{
|
|
||||||
"OperationID": OperationID,
|
|
||||||
"PID": logger.Pid,
|
|
||||||
}).Debugln(v.Args, args)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ErrorWithCtx(ctx context.Context, args ...interface{}) {
|
|
||||||
t := ctx.Value(tracelog.TraceLogKey).(*tracelog.FuncInfos)
|
|
||||||
OperationID := tracelog.GetOperationID(ctx)
|
|
||||||
for _, v := range *t.Funcs {
|
|
||||||
if v.Err != nil {
|
|
||||||
logger.WithFields(logrus.Fields{
|
|
||||||
"OperationID": OperationID,
|
|
||||||
"PID": logger.Pid,
|
|
||||||
}).Errorln(v.Err, v.Args, args)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WarnWithCtx(ctx context.Context, args ...interface{}) {
|
|
||||||
t := ctx.Value(tracelog.TraceLogKey).(*tracelog.FuncInfos)
|
|
||||||
OperationID := tracelog.GetOperationID(ctx)
|
|
||||||
for _, v := range *t.Funcs {
|
|
||||||
logger.WithFields(logrus.Fields{
|
|
||||||
"OperationID": OperationID,
|
|
||||||
"PID": logger.Pid,
|
|
||||||
}).Warnln(v.Args, args)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user