From 488ebee8443e162ee9fccbcf92d16b06960cd696 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Wed, 30 Jun 2021 16:28:05 +0800 Subject: [PATCH] add msgid in log --- routers/repo/blockchain.go | 18 +++++++++--------- routers/repo/cloudbrain.go | 2 +- routers/routes/routes.go | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/routers/repo/blockchain.go b/routers/repo/blockchain.go index d650e71ca..dc3fcd848 100755 --- a/routers/repo/blockchain.go +++ b/routers/repo/blockchain.go @@ -28,14 +28,14 @@ const ( func BlockChainIndex(ctx *context.Context) { repo := ctx.Repo.Repository if repo.ContractAddress == "" || ctx.User.PublicKey == "" { - log.Error("the repo(%d) or the user(%d) has not been initialized in block_chain", repo.RepoID, ctx.User.ID) + log.Error("the repo(%d) or the user(%d) has not been initialized in block_chain", repo.RepoID, ctx.User.ID, ctx.Data["msgID"]) ctx.HTML(http.StatusInternalServerError, tplBlockChainIndex) return } res, err := blockchain.GetBalance(repo.ContractAddress, ctx.User.PublicKey) if err != nil { - log.Error("GetBalance(%s) failed:%v", ctx.User.PublicKey, err) + log.Error("GetBalance(%s) failed:%s", ctx.User.PublicKey, err, ctx.Data["msgID"]) ctx.HTML(http.StatusInternalServerError, tplBlockChainIndex) return } @@ -52,7 +52,7 @@ func HandleBlockChainInitNotify(ctx *context.Context) { repo, err := models.GetRepositoryByID(req.RepoId) if err != nil { - log.Error("GetRepositoryByID failed:", err.Error()) + log.Error("GetRepositoryByID failed:%v", err.Error(), ctx.Data["msgID"]) ctx.JSON(200, map[string]string{ "code": "-1", "message": "internal error", @@ -61,7 +61,7 @@ func HandleBlockChainInitNotify(ctx *context.Context) { } if repo.BlockChainStatus == models.RepoBlockChainSuccess && len(repo.ContractAddress) != 0 { - log.Error("the repo has been RepoBlockChainSuccess:", req.RepoId) + log.Error("the repo has been RepoBlockChainSuccess:%d", req.RepoId, ctx.Data["msgID"]) ctx.JSON(200, map[string]string{ "code": "-1", "message": "the repo has been RepoBlockChainSuccess", @@ -73,7 +73,7 @@ func HandleBlockChainInitNotify(ctx *context.Context) { repo.ContractAddress = req.ContractAddress if err = models.UpdateRepositoryCols(repo, "block_chain_status", "contract_address"); err != nil { - log.Error("UpdateRepositoryCols failed:", err.Error()) + log.Error("UpdateRepositoryCols failed:%v", err.Error(), ctx.Data["msgID"]) ctx.JSON(200, map[string]string{ "code": "-1", "message": "internal error", @@ -91,7 +91,7 @@ func HandleBlockChainCommitNotify(ctx *context.Context) { var req BlockChainCommitNotify data, _ := ctx.Req.Body().Bytes() if err := json.Unmarshal(data, &req); err != nil { - log.Error("json.Unmarshal failed:", err.Error()) + log.Error("json.Unmarshal failed:%v", err.Error(), ctx.Data["msgID"]) ctx.JSON(200, map[string]string{ "code": "-1", "message": "response data error", @@ -101,7 +101,7 @@ func HandleBlockChainCommitNotify(ctx *context.Context) { blockChain, err := models.GetBlockChainByCommitID(req.CommitID) if err != nil { - log.Error("GetRepositoryByID failed:", err.Error()) + log.Error("GetRepositoryByID failed:%v", err.Error(), ctx.Data["msgID"]) ctx.JSON(200, map[string]string{ "code": "-1", "message": "internal error", @@ -110,7 +110,7 @@ func HandleBlockChainCommitNotify(ctx *context.Context) { } if blockChain.Status == models.BlockChainCommitSuccess { - log.Error("the commit has been BlockChainCommitReady:", blockChain.RepoID) + log.Error("the commit has been BlockChainCommitReady:%s", blockChain.RepoID, ctx.Data["msgID"]) ctx.JSON(200, map[string]string{ "code": "-1", "message": "the commit has been BlockChainCommitReady", @@ -122,7 +122,7 @@ func HandleBlockChainCommitNotify(ctx *context.Context) { blockChain.TransactionHash = req.TransactionHash if err = models.UpdateBlockChainCols(blockChain, "status", "transaction_hash"); err != nil { - log.Error("UpdateBlockChainCols failed:", err.Error()) + log.Error("UpdateBlockChainCols failed:%v", err.Error(), ctx.Data["msgID"]) ctx.JSON(200, map[string]string{ "code": "-1", "message": "internal error", diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index a2a65fd81..27642d7bb 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -417,7 +417,7 @@ func GetRate(ctx *context.Context) { func downloadCode(repo *models.Repository, codePath string) error { if err := git.Clone(repo.RepoPath(), codePath, git.CloneRepoOptions{}); err != nil { - log.Error("Failed to clone repository: %s (%v)", repo.FullName(), err, ctx.Data["msgID"]) + log.Error("Failed to clone repository: %s (%v)", repo.FullName(), err) return err } diff --git a/routers/routes/routes.go b/routers/routes/routes.go index d994ec5bf..4f1f6f314 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -108,7 +108,7 @@ func RouterHandler(level log.Level) func(ctx *macaron.Context) { } } -// SetLogMsgID set msgID in log +// SetLogMsgID set msgID in Context func SetLogMsgID() func(ctx *macaron.Context) { return func(ctx *macaron.Context) { start := time.Now()