From 1cf071a444378c05ae6b5453da1c43a36700de8c Mon Sep 17 00:00:00 2001 From: duanhf2012 <6549168@qq.com> Date: Fri, 20 Sep 2024 15:17:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cluster/cluster.go | 4 ++-- node/node.go | 4 ++-- profiler/profiler.go | 8 ++------ sysmodule/ginmodule/GinModule.go | 2 +- sysmodule/ginmodule/logger.go | 2 +- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/cluster/cluster.go b/cluster/cluster.go index 1c3e06e..2f5bf9f 100644 --- a/cluster/cluster.go +++ b/cluster/cluster.go @@ -297,12 +297,12 @@ func GetRpcClient(nodeId string, serviceMethod string,filterRetire bool, clientL if nodeId != rpc.NodeIdNull { pClient,retire := GetCluster().GetRpcClient(nodeId) 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 { - return fmt.Errorf("cannot find nodeid %d!", nodeId), nil + return fmt.Errorf("cannot find nodeid %s", nodeId), nil } clientList = append(clientList,pClient) diff --git a/node/node.go b/node/node.go index d1ba6e8..0d51949 100644 --- a/node/node.go +++ b/node/node.go @@ -328,13 +328,13 @@ func startNode(args interface{}) error { myName, mErr := sysprocess.GetMyProcessName() //当前进程名获取失败,不应该发生 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) } //进程id存在,而且进程名也相同,被认为是当前进程重复运行 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) } break diff --git a/profiler/profiler.go b/profiler/profiler.go index 1676cb8..38a3c98 100644 --- a/profiler/profiler.go +++ b/profiler/profiler.go @@ -145,14 +145,12 @@ func DefaultReportFunction(name string,callNum int,costTime time.Duration,record return } - var strReport string - strReport = "Profiler report tag "+name+":\n" var average int64 if callNum>0 { 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() var strTypes string for elem!=nil { @@ -163,11 +161,9 @@ func DefaultReportFunction(name string,callNum int,costTime time.Duration,record 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() } - - log.SInfo("report",strReport) } func Report() { diff --git a/sysmodule/ginmodule/GinModule.go b/sysmodule/ginmodule/GinModule.go index fc00f5e..1fcf362 100644 --- a/sysmodule/ginmodule/GinModule.go +++ b/sysmodule/ginmodule/GinModule.go @@ -90,7 +90,7 @@ func (gm *GinModule) StartTLS(certFile, keyFile string) { func (gm *GinModule) Stop(ctx context.Context) { if err := gm.srv.Shutdown(ctx); err != nil { - log.SError("Server Shutdown", slog.Any("error", err)) + log.Error("Server Shutdown", slog.Any("error", err)) } } diff --git a/sysmodule/ginmodule/logger.go b/sysmodule/ginmodule/logger.go index c9e8d07..83c8df0 100644 --- a/sysmodule/ginmodule/logger.go +++ b/sysmodule/ginmodule/logger.go @@ -44,7 +44,7 @@ func Logger() gin.HandlerFunc { // 响应状态码 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\"", colorForStatus(statusCode), statusCode,