优化日志

This commit is contained in:
duanhf2012
2024-09-20 15:17:44 +08:00
parent e6c09064bf
commit 1cf071a444
5 changed files with 8 additions and 12 deletions

View File

@@ -297,12 +297,12 @@ func GetRpcClient(nodeId string, serviceMethod string,filterRetire bool, clientL
if nodeId != rpc.NodeIdNull { if nodeId != rpc.NodeIdNull {
pClient,retire := GetCluster().GetRpcClient(nodeId) pClient,retire := GetCluster().GetRpcClient(nodeId)
if pClient == nil { if pClient == nil {
return fmt.Errorf("cannot find nodeid %d!", nodeId), nil return fmt.Errorf("cannot find nodeid %s", nodeId), nil
} }
//如果需要筛选掉退休结点 //如果需要筛选掉退休结点
if filterRetire == true && retire == true { if filterRetire == true && retire == true {
return fmt.Errorf("cannot find nodeid %d!", nodeId), nil return fmt.Errorf("cannot find nodeid %s", nodeId), nil
} }
clientList = append(clientList,pClient) clientList = append(clientList,pClient)

View File

@@ -328,13 +328,13 @@ func startNode(args interface{}) error {
myName, mErr := sysprocess.GetMyProcessName() myName, mErr := sysprocess.GetMyProcessName()
//当前进程名获取失败,不应该发生 //当前进程名获取失败,不应该发生
if mErr != nil { if mErr != nil {
log.SInfo("get my process's name is error,", mErr.Error()) log.Info("get my process's name is error",log.ErrorAttr("err", mErr))
os.Exit(-1) os.Exit(-1)
} }
//进程id存在而且进程名也相同被认为是当前进程重复运行 //进程id存在而且进程名也相同被认为是当前进程重复运行
if cErr == nil && name == myName { if cErr == nil && name == myName {
log.SInfo(fmt.Sprintf("repeat runs are not allowed,node is %s,processid is %d",strNodeId,processId)) log.Info("repeat runs are not allowed",log.String("nodeId",strNodeId),log.Int("processId",processId))
os.Exit(-1) os.Exit(-1)
} }
break break

View File

@@ -145,14 +145,12 @@ func DefaultReportFunction(name string,callNum int,costTime time.Duration,record
return return
} }
var strReport string
strReport = "Profiler report tag "+name+":\n"
var average int64 var average int64
if callNum>0 { if callNum>0 {
average = costTime.Milliseconds()/int64(callNum) average = costTime.Milliseconds()/int64(callNum)
} }
strReport += fmt.Sprintf("process count %d,take time %d Milliseconds,average %d Milliseconds/per.\n",callNum,costTime.Milliseconds(),average) log.Info("Profiler report tag "+name,log.Int("process count",callNum),log.Int64("take time",costTime.Milliseconds()),log.Int64("average",average))
elem := record.Front() elem := record.Front()
var strTypes string var strTypes string
for elem!=nil { for elem!=nil {
@@ -163,11 +161,9 @@ func DefaultReportFunction(name string,callNum int,costTime time.Duration,record
strTypes = "slow process" strTypes = "slow process"
} }
strReport += fmt.Sprintf("%s:%s is take %d Milliseconds\n",strTypes,pRecord.RecordName,pRecord.CostTime.Milliseconds()) log.Info("Profiler report type",log.String("Types",strTypes),log.String("RecordName",pRecord.RecordName),log.Int64("take time",pRecord.CostTime.Milliseconds()))
elem = elem.Next() elem = elem.Next()
} }
log.SInfo("report",strReport)
} }
func Report() { func Report() {

View File

@@ -90,7 +90,7 @@ func (gm *GinModule) StartTLS(certFile, keyFile string) {
func (gm *GinModule) Stop(ctx context.Context) { func (gm *GinModule) Stop(ctx context.Context) {
if err := gm.srv.Shutdown(ctx); err != nil { if err := gm.srv.Shutdown(ctx); err != nil {
log.SError("Server Shutdown", slog.Any("error", err)) log.Error("Server Shutdown", slog.Any("error", err))
} }
} }

View File

@@ -44,7 +44,7 @@ func Logger() gin.HandlerFunc {
// 响应状态码 // 响应状态码
statusCode := c.Writer.Status() statusCode := c.Writer.Status()
log.SDebug(fmt.Sprintf( log.Debug(fmt.Sprintf(
"%s | %3d | %s %10s | \033[44;37m%-6s\033[0m %s %s | %10v | \"%s\" \"%s\"", "%s | %3d | %s %10s | \033[44;37m%-6s\033[0m %s %s | %10v | \"%s\" \"%s\"",
colorForStatus(statusCode), colorForStatus(statusCode),
statusCode, statusCode,