From 0791023038f60e75cb93e5d73539b439b630fadd Mon Sep 17 00:00:00 2001 From: Wangjunqi123 Date: Sat, 2 Sep 2023 17:38:11 +0800 Subject: [PATCH 1/2] =?UTF-8?q?topo=20=E6=8F=92=E4=BB=B6agent=E9=9B=86?= =?UTF-8?q?=E7=BE=A4=E4=BF=A1=E6=81=AF=E9=87=87=E9=9B=86=EF=BC=9Bserver?= =?UTF-8?q?=E7=AB=AF=E9=87=87=E9=9B=86=E6=95=B0=E6=8D=AE=E6=B1=87=E6=80=BB?= =?UTF-8?q?=E3=80=81=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sdk/logger/logger.go | 308 +++++++++++++++++++++---------------------- 1 file changed, 154 insertions(+), 154 deletions(-) diff --git a/sdk/logger/logger.go b/sdk/logger/logger.go index 6fbb8c57..102608c7 100644 --- a/sdk/logger/logger.go +++ b/sdk/logger/logger.go @@ -1,154 +1,154 @@ -/****************************************************************************** - * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved. - * PilotGo is licensed under the Mulan PSL v2. - * You can use this software accodring to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - * Author: yangzhao1 - * Date: 2022-03-01 09:59:30 - * LastEditTime: 2022-04-05 11:37:16 - * Description: provide agent log manager of pilotgo - ******************************************************************************/ -package logger - -import ( - "errors" - "os" - "time" - - "github.com/gin-gonic/gin" - rotatelogs "github.com/lestrrat-go/file-rotatelogs" - "github.com/sirupsen/logrus" -) - -type LogOpts struct { - Level string `yaml:"level"` - Driver string `yaml:"driver"` - Path string `yaml:"path"` - MaxFile int `yaml:"max_file"` - MaxSize int `yaml:"max_size"` -} - -func setLogDriver(logopts *LogOpts) error { - if logopts == nil { - return errors.New("logopts is nil") - } - - switch logopts.Driver { - case "stdout": - logrus.SetOutput(os.Stdout) - case "file": - writer, err := rotatelogs.New( - logopts.Path, - rotatelogs.WithRotationCount(uint(logopts.MaxFile)), - rotatelogs.WithRotationSize(int64(logopts.MaxSize)), - ) - if err != nil { - return err - } - logrus.SetFormatter(&logrus.TextFormatter{ - DisableColors: true, - ForceQuote: false, - TimestampFormat: "2006-01-02 15:04:05", - }) - logrus.SetOutput(writer) - default: - logrus.SetOutput(os.Stdout) - logrus.Warn("!!! invalid log output, use stdout !!!") - } - return nil -} - -func setLogLevel(logopts *LogOpts) error { - switch logopts.Level { - case "trace": - logrus.SetLevel(logrus.TraceLevel) - case "debug": - logrus.SetLevel(logrus.DebugLevel) - case "info": - logrus.SetLevel(logrus.InfoLevel) - case "warn": - logrus.SetLevel(logrus.WarnLevel) - case "error": - logrus.SetLevel(logrus.ErrorLevel) - case "fatal": - logrus.SetLevel(logrus.FatalLevel) - default: - return errors.New("invalid log level") - } - return nil -} -func Init(conf *LogOpts) error { - setLogLevel(conf) - err := setLogDriver(conf) - if err != nil { - return err - } - logrus.Debug("log init") - - return nil -} - -func LoggerDebug() gin.HandlerFunc { - return func(c *gin.Context) { - // 开始时间 - startTime := time.Now() - - // 处理请求 - c.Next() - - // 结束时间 - endTime := time.Now() - - // 执行时间 - latencyTime := endTime.Sub(startTime) - - // 请求方式 - reqMethod := c.Request.Method - - // 请求路由 - reqUri := c.Request.RequestURI - - // 状态码 - statusCode := c.Writer.Status() - - // 请求IP - clientIP := c.ClientIP() - - // 日志格式 - Debug("status_code:%d latency_time:%s client_ip:%s req_method:%s req_uri:%s", - statusCode, - latencyTime, - clientIP, - reqMethod, - reqUri, - ) - } -} - -func Trace(format string, args ...interface{}) { - logrus.Tracef(format, args...) -} - -func Debug(format string, args ...interface{}) { - logrus.Debugf(format, args...) -} - -func Info(format string, args ...interface{}) { - logrus.Infof(format, args...) -} - -func Warn(format string, args ...interface{}) { - logrus.Warnf(format, args...) -} - -func Error(format string, args ...interface{}) { - logrus.Errorf(format, args...) -} - -func Fatal(format string, args ...interface{}) { - logrus.Fatalf(format, args...) -} +/****************************************************************************** + * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved. + * PilotGo is licensed under the Mulan PSL v2. + * You can use this software accodring to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * Author: yangzhao1 + * Date: 2022-03-01 09:59:30 + * LastEditTime: 2022-04-05 11:37:16 + * Description: provide agent log manager of pilotgo + ******************************************************************************/ +package logger + +import ( + "errors" + "os" + "time" + + "github.com/gin-gonic/gin" + rotatelogs "github.com/lestrrat-go/file-rotatelogs" + "github.com/sirupsen/logrus" +) + +type LogOpts struct { + Level string `yaml:"level"` + Driver string `yaml:"driver"` + Path string `yaml:"path"` + MaxFile int `yaml:"max_file"` + MaxSize int `yaml:"max_size"` +} + +func setLogDriver(logopts *LogOpts) error { + if logopts == nil { + return errors.New("logopts is nil") + } + + switch logopts.Driver { + case "stdout": + logrus.SetOutput(os.Stdout) + case "file": + writer, err := rotatelogs.New( + logopts.Path, + rotatelogs.WithRotationCount(uint(logopts.MaxFile)), + rotatelogs.WithRotationSize(int64(logopts.MaxSize)), + ) + if err != nil { + return err + } + logrus.SetFormatter(&logrus.TextFormatter{ + DisableColors: true, + ForceQuote: false, + TimestampFormat: "2006-01-02 15:04:05", + }) + logrus.SetOutput(writer) + default: + logrus.SetOutput(os.Stdout) + logrus.Warn("!!! invalid log output, use stdout !!!") + } + return nil +} + +func setLogLevel(logopts *LogOpts) error { + switch logopts.Level { + case "trace": + logrus.SetLevel(logrus.TraceLevel) + case "debug": + logrus.SetLevel(logrus.DebugLevel) + case "info": + logrus.SetLevel(logrus.InfoLevel) + case "warn": + logrus.SetLevel(logrus.WarnLevel) + case "error": + logrus.SetLevel(logrus.ErrorLevel) + case "fatal": + logrus.SetLevel(logrus.FatalLevel) + default: + return errors.New("invalid log level") + } + return nil +} +func Init(conf *LogOpts) error { + setLogLevel(conf) + err := setLogDriver(conf) + if err != nil { + return err + } + logrus.Debug("log init") + + return nil +} + +func LoggerDebug() gin.HandlerFunc { + return func(c *gin.Context) { + // 开始时间 + startTime := time.Now() + + // 处理请求 + c.Next() + + // 结束时间 + endTime := time.Now() + + // 执行时间 + latencyTime := endTime.Sub(startTime) + + // 请求方式 + reqMethod := c.Request.Method + + // 请求路由 + reqUri := c.Request.RequestURI + + // 状态码 + statusCode := c.Writer.Status() + + // 请求IP + clientIP := c.ClientIP() + + // 日志格式 + Debug("status_code:%d latency_time:%s client_ip:%s req_method:%s req_uri:%s", + statusCode, + latencyTime, + clientIP, + reqMethod, + reqUri, + ) + } +} + +func Trace(format string, args ...interface{}) { + logrus.Tracef(format, args...) +} + +func Debug(format string, args ...interface{}) { + logrus.Debugf(format, args...) +} + +func Info(format string, args ...interface{}) { + logrus.Infof(format, args...) +} + +func Warn(format string, args ...interface{}) { + logrus.Warnf(format, args...) +} + +func Error(format string, args ...interface{}) { + logrus.Errorf(format, args...) +} + +func Fatal(format string, args ...interface{}) { + logrus.Fatalf(format, args...) +} -- Gitee From f41e5c47dfa6ede17e31bc6459c93474b3f46f4f Mon Sep 17 00:00:00 2001 From: Wangjunqi123 Date: Tue, 5 Sep 2023 14:32:17 +0800 Subject: [PATCH 2/2] fix initmachinelist() bug; add build file --- .gitignore | 6 +- sdk/logger/logger.go | 308 ++++++++++----------- topology/build | 34 +++ topology/server/agentmanager/topoclient.go | 26 +- topology/server/collector/collector.go | 6 +- topology/server/utils/error.go | 12 +- 6 files changed, 215 insertions(+), 177 deletions(-) create mode 100644 topology/build diff --git a/.gitignore b/.gitignore index 015eb5f2..7a279ffc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ -/PilotGo -.DS_Store -/.vscode \ No newline at end of file + +.vscode/ +!build \ No newline at end of file diff --git a/sdk/logger/logger.go b/sdk/logger/logger.go index 102608c7..6fbb8c57 100644 --- a/sdk/logger/logger.go +++ b/sdk/logger/logger.go @@ -1,154 +1,154 @@ -/****************************************************************************** - * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved. - * PilotGo is licensed under the Mulan PSL v2. - * You can use this software accodring to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - * Author: yangzhao1 - * Date: 2022-03-01 09:59:30 - * LastEditTime: 2022-04-05 11:37:16 - * Description: provide agent log manager of pilotgo - ******************************************************************************/ -package logger - -import ( - "errors" - "os" - "time" - - "github.com/gin-gonic/gin" - rotatelogs "github.com/lestrrat-go/file-rotatelogs" - "github.com/sirupsen/logrus" -) - -type LogOpts struct { - Level string `yaml:"level"` - Driver string `yaml:"driver"` - Path string `yaml:"path"` - MaxFile int `yaml:"max_file"` - MaxSize int `yaml:"max_size"` -} - -func setLogDriver(logopts *LogOpts) error { - if logopts == nil { - return errors.New("logopts is nil") - } - - switch logopts.Driver { - case "stdout": - logrus.SetOutput(os.Stdout) - case "file": - writer, err := rotatelogs.New( - logopts.Path, - rotatelogs.WithRotationCount(uint(logopts.MaxFile)), - rotatelogs.WithRotationSize(int64(logopts.MaxSize)), - ) - if err != nil { - return err - } - logrus.SetFormatter(&logrus.TextFormatter{ - DisableColors: true, - ForceQuote: false, - TimestampFormat: "2006-01-02 15:04:05", - }) - logrus.SetOutput(writer) - default: - logrus.SetOutput(os.Stdout) - logrus.Warn("!!! invalid log output, use stdout !!!") - } - return nil -} - -func setLogLevel(logopts *LogOpts) error { - switch logopts.Level { - case "trace": - logrus.SetLevel(logrus.TraceLevel) - case "debug": - logrus.SetLevel(logrus.DebugLevel) - case "info": - logrus.SetLevel(logrus.InfoLevel) - case "warn": - logrus.SetLevel(logrus.WarnLevel) - case "error": - logrus.SetLevel(logrus.ErrorLevel) - case "fatal": - logrus.SetLevel(logrus.FatalLevel) - default: - return errors.New("invalid log level") - } - return nil -} -func Init(conf *LogOpts) error { - setLogLevel(conf) - err := setLogDriver(conf) - if err != nil { - return err - } - logrus.Debug("log init") - - return nil -} - -func LoggerDebug() gin.HandlerFunc { - return func(c *gin.Context) { - // 开始时间 - startTime := time.Now() - - // 处理请求 - c.Next() - - // 结束时间 - endTime := time.Now() - - // 执行时间 - latencyTime := endTime.Sub(startTime) - - // 请求方式 - reqMethod := c.Request.Method - - // 请求路由 - reqUri := c.Request.RequestURI - - // 状态码 - statusCode := c.Writer.Status() - - // 请求IP - clientIP := c.ClientIP() - - // 日志格式 - Debug("status_code:%d latency_time:%s client_ip:%s req_method:%s req_uri:%s", - statusCode, - latencyTime, - clientIP, - reqMethod, - reqUri, - ) - } -} - -func Trace(format string, args ...interface{}) { - logrus.Tracef(format, args...) -} - -func Debug(format string, args ...interface{}) { - logrus.Debugf(format, args...) -} - -func Info(format string, args ...interface{}) { - logrus.Infof(format, args...) -} - -func Warn(format string, args ...interface{}) { - logrus.Warnf(format, args...) -} - -func Error(format string, args ...interface{}) { - logrus.Errorf(format, args...) -} - -func Fatal(format string, args ...interface{}) { - logrus.Fatalf(format, args...) -} +/****************************************************************************** + * Copyright (c) KylinSoft Co., Ltd.2021-2022. All rights reserved. + * PilotGo is licensed under the Mulan PSL v2. + * You can use this software accodring to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + * Author: yangzhao1 + * Date: 2022-03-01 09:59:30 + * LastEditTime: 2022-04-05 11:37:16 + * Description: provide agent log manager of pilotgo + ******************************************************************************/ +package logger + +import ( + "errors" + "os" + "time" + + "github.com/gin-gonic/gin" + rotatelogs "github.com/lestrrat-go/file-rotatelogs" + "github.com/sirupsen/logrus" +) + +type LogOpts struct { + Level string `yaml:"level"` + Driver string `yaml:"driver"` + Path string `yaml:"path"` + MaxFile int `yaml:"max_file"` + MaxSize int `yaml:"max_size"` +} + +func setLogDriver(logopts *LogOpts) error { + if logopts == nil { + return errors.New("logopts is nil") + } + + switch logopts.Driver { + case "stdout": + logrus.SetOutput(os.Stdout) + case "file": + writer, err := rotatelogs.New( + logopts.Path, + rotatelogs.WithRotationCount(uint(logopts.MaxFile)), + rotatelogs.WithRotationSize(int64(logopts.MaxSize)), + ) + if err != nil { + return err + } + logrus.SetFormatter(&logrus.TextFormatter{ + DisableColors: true, + ForceQuote: false, + TimestampFormat: "2006-01-02 15:04:05", + }) + logrus.SetOutput(writer) + default: + logrus.SetOutput(os.Stdout) + logrus.Warn("!!! invalid log output, use stdout !!!") + } + return nil +} + +func setLogLevel(logopts *LogOpts) error { + switch logopts.Level { + case "trace": + logrus.SetLevel(logrus.TraceLevel) + case "debug": + logrus.SetLevel(logrus.DebugLevel) + case "info": + logrus.SetLevel(logrus.InfoLevel) + case "warn": + logrus.SetLevel(logrus.WarnLevel) + case "error": + logrus.SetLevel(logrus.ErrorLevel) + case "fatal": + logrus.SetLevel(logrus.FatalLevel) + default: + return errors.New("invalid log level") + } + return nil +} +func Init(conf *LogOpts) error { + setLogLevel(conf) + err := setLogDriver(conf) + if err != nil { + return err + } + logrus.Debug("log init") + + return nil +} + +func LoggerDebug() gin.HandlerFunc { + return func(c *gin.Context) { + // 开始时间 + startTime := time.Now() + + // 处理请求 + c.Next() + + // 结束时间 + endTime := time.Now() + + // 执行时间 + latencyTime := endTime.Sub(startTime) + + // 请求方式 + reqMethod := c.Request.Method + + // 请求路由 + reqUri := c.Request.RequestURI + + // 状态码 + statusCode := c.Writer.Status() + + // 请求IP + clientIP := c.ClientIP() + + // 日志格式 + Debug("status_code:%d latency_time:%s client_ip:%s req_method:%s req_uri:%s", + statusCode, + latencyTime, + clientIP, + reqMethod, + reqUri, + ) + } +} + +func Trace(format string, args ...interface{}) { + logrus.Tracef(format, args...) +} + +func Debug(format string, args ...interface{}) { + logrus.Debugf(format, args...) +} + +func Info(format string, args ...interface{}) { + logrus.Infof(format, args...) +} + +func Warn(format string, args ...interface{}) { + logrus.Warnf(format, args...) +} + +func Error(format string, args ...interface{}) { + logrus.Errorf(format, args...) +} + +func Fatal(format string, args ...interface{}) { + logrus.Fatalf(format, args...) +} diff --git a/topology/build b/topology/build new file mode 100644 index 00000000..350fd41b --- /dev/null +++ b/topology/build @@ -0,0 +1,34 @@ +#!/bin/bash + + +SERVERMAIN="/home/wjq/a-disk/PilotGo-plugins/topology/server/main.go" +SERVERSCRIPT="/home/wjq/a-disk/PilotGo-plugins/topology/toposerver" +AGENTMAIN="/home/wjq/a-disk/PilotGo-plugins/topology/agent/main.go" +AGENTSCRIPT="/home/wjq/a-disk/PilotGo-plugins/topology/topoagent" +AGENTREMOTE="/opt/topo" + +echo -e "\e[32m build server \e[0m" +go build -o $SERVERSCRIPT ${SERVERMAIN} +echo -e "\e[32m build agent \e[0m" +go build -o $AGENTSCRIPT $AGENTMAIN + +case "x$#" in + x1) + echo -e "\e[32m upload to $1 \e[0m" + scp $AGENTSCRIPT root@192.168.75.$1:$AGENTREMOTE > /dev/null + ;; + x2) + echo -e "\e[32m upload to $1 \e[0m" + scp $AGENTSCRIPT root@192.168.75.$1:$AGENTREMOTE > /dev/null + echo -e "\e[32m upload to $2 \e[0m" + scp $AGENTSCRIPT root@192.168.75.$2:$AGENTREMOTE > /dev/null + ;; + x3) + echo -e "\e[32m upload to $1 \e[0m" + scp $AGENTSCRIPT root@192.168.75.$1:$AGENTREMOTE > /dev/null + echo -e "\e[32m upload to $2 \e[0m" + scp $AGENTSCRIPT root@192.168.75.$2:$AGENTREMOTE > /dev/null + echo -e "\e[32m upload to $3 \e[0m" + scp $AGENTSCRIPT root@192.168.75.$3:$AGENTREMOTE > /dev/null + ;; +esac diff --git a/topology/server/agentmanager/topoclient.go b/topology/server/agentmanager/topoclient.go index 38f367d4..c855896a 100644 --- a/topology/server/agentmanager/topoclient.go +++ b/topology/server/agentmanager/topoclient.go @@ -25,24 +25,28 @@ type Topoclient struct { func (t *Topoclient) InitMachineList() { url := Topo.Sdkmethod.Server + "/api/v1/pluginapi/machine_list" - r, err := httputils.Get(url, nil) + resp, err := httputils.Get(url, nil) if err != nil { - filepath, line, funcname := utils.CallerInfo(err) + filepath, line, funcname := utils.CallerInfo() logger.Error("\n\tfile: %s\n\tline: %d\n\tfunc: %s\n\terr: %s\n", filepath, line, funcname, err.Error()) + return } - results := &struct { - Code int `json:"code"` - Data interface{} `json:"data"` - }{} + statuscode := resp.StatusCode + if statuscode != 200 { + filepath, line, funcname := utils.CallerInfo() + logger.Error("\n\tfile: %s\n\tline: %d\n\tfunc: %s\n\terr: %s\n", filepath, line, funcname, string(resp.Body)) + return + } - err = json.Unmarshal(r.Body, &results) + agents := &[]interface{}{} + err = json.Unmarshal(resp.Body, agents) if err != nil { - filepath, line, funcname := utils.CallerInfo(err) + filepath, line, funcname := utils.CallerInfo() logger.Error("\n\tfile: %s\n\tline: %d\n\tfunc: %s\n\terr: %s\n", filepath, line, funcname, err.Error()) } - for _, m := range results.Data.([]interface{}) { + for _, m := range *agents { p := &Agent_m{} mapstructure.Decode(m, p) p.TAState = 0 @@ -53,7 +57,7 @@ func (t *Topoclient) InitMachineList() { func (t *Topoclient) InitLogger() { err := logger.Init(conf.Config().Logopts) if err != nil { - filepath, line, funcname := utils.CallerInfo(err) + filepath, line, funcname := utils.CallerInfo() logger.Error("\n\tfile: %s\n\tline: %d\n\tfunc: %s\n\terr: %s\n", filepath, line, funcname, err.Error()) os.Exit(1) } @@ -65,7 +69,7 @@ func (t *Topoclient) InitWebServer() { handler.InitRouter(engine) err := engine.Run(conf.Config().Topo.Server_addr) if err != nil { - filepath, line, funcname := utils.CallerInfo(err) + filepath, line, funcname := utils.CallerInfo() logger.Fatal("\n\tfile: %s\n\tline: %d\n\tfunc: %s\n\terr: %s\n", filepath, line, funcname, err.Error()) } } diff --git a/topology/server/collector/collector.go b/topology/server/collector/collector.go index 6559a995..0b431cda 100644 --- a/topology/server/collector/collector.go +++ b/topology/server/collector/collector.go @@ -34,7 +34,7 @@ func (d *DataCollector) Collect_instant_data() error { agent.Port = conf.Config().Topo.Agent_port err := d.GetCollectDataFromTopoAgent(agent) if err != nil { - filepath, line, funcname := utils.CallerInfo(err) + filepath, line, funcname := utils.CallerInfo() logger.Error("\n\tfile: %s\n\tline: %d\n\tfunc: %s\n", filepath, line, funcname) } agentmanager.Topo.AddAgent(agent) @@ -56,7 +56,7 @@ func (d *DataCollector) GetCollectDataFromTopoAgent(a *agentmanager.Agent_m) err r, err := httputils.Get(url, nil) if err != nil { - filepath, line, funcname := utils.CallerInfo(err) + filepath, line, funcname := utils.CallerInfo() logger.Error("\n\tfile: %s\n\tline: %d\n\tfunc: %s\n\terr: %s\n", filepath, line, funcname, err.Error()) return fmt.Errorf("file: %s, line: %d, func: %s, err -> %s", filepath, line, funcname, err.Error()) } @@ -69,7 +69,7 @@ func (d *DataCollector) GetCollectDataFromTopoAgent(a *agentmanager.Agent_m) err err = json.Unmarshal(r.Body, &results) if err != nil { - filepath, line, funcname := utils.CallerInfo(err) + filepath, line, funcname := utils.CallerInfo() logger.Error("\n\tfile: %s\n\tline: %d\n\tfunc: %s\n\terr: %s\n", filepath, line, funcname, err.Error()) return fmt.Errorf("file: %s, line: %d, func: %s, err -> %s", filepath, line, funcname, err.Error()) } diff --git a/topology/server/utils/error.go b/topology/server/utils/error.go index 249aeb44..9d43ae52 100644 --- a/topology/server/utils/error.go +++ b/topology/server/utils/error.go @@ -2,12 +2,12 @@ package utils import "runtime" -func CallerInfo(err error) (string, int, string) { - if err != nil { - pro_c, filepath, line, ok := runtime.Caller(1) - if ok { - return filepath, line - 2, runtime.FuncForPC(pro_c).Name() - } +func CallerInfo() (string, int, string) { + // if err != nil { + pro_c, filepath, line, ok := runtime.Caller(1) + if ok { + return filepath, line - 2, runtime.FuncForPC(pro_c).Name() } + // } return "", -1, "" } -- Gitee