From a880aaf054030ff6b4a1d91bf96272f88c7fe038 Mon Sep 17 00:00:00 2001 From: Medzik Date: Sun, 7 Nov 2021 19:19:06 +0000 Subject: [PATCH] fix(log): update trace error log --- database/mongo/connect.go | 8 ++++++-- ping/ping.go | 4 +++- website/routes/api/status.go | 4 +++- website/server.go | 4 +++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/database/mongo/connect.go b/database/mongo/connect.go index cf8fbd2..e5bfe77 100644 --- a/database/mongo/connect.go +++ b/database/mongo/connect.go @@ -20,14 +20,18 @@ func Connect() error { defer cancel() Client, err := mongo.Connect(ctx, options.Client().ApplyURI(config.Mongo_URI)) - if common.CheckErr(err, "connect to db") { + if err != nil { + common.Log.Error("connect to db", err) + time.Sleep(2 * time.Second) return err } err = Client.Ping(ctx, readpref.Primary()) - if common.CheckErr(err, "ping db") { + if err != nil { + common.Log.Error("ping db", err) + time.Sleep(2 * time.Second) return err diff --git a/ping/ping.go b/ping/ping.go index 9e99cf0..050ba37 100644 --- a/ping/ping.go +++ b/ping/ping.go @@ -25,7 +25,9 @@ func loop(url string) { defer cancel() req, err := http.NewRequestWithContext(ctx, "GET", url, nil) - if common.CheckErr(err, "new http request") { + if err != nil { + common.Log.Error("new http request", err) + Status.Error++ return diff --git a/website/routes/api/status.go b/website/routes/api/status.go index 8afd193..eb48137 100644 --- a/website/routes/api/status.go +++ b/website/routes/api/status.go @@ -17,7 +17,9 @@ func Status(c *gin.Context) { mem := stats.Memory() cpu, err := stats.CPU() - common.CheckErr(err, "cpu stat") + if err != nil { + common.Log.Error("cpu stat", err) + } var p json diff --git a/website/server.go b/website/server.go index 0fb58a0..e1f9420 100644 --- a/website/server.go +++ b/website/server.go @@ -31,7 +31,9 @@ func Server() { api.ApplyRoutes(router) err := router.Run(":" + strconv.Itoa(config.Toml.HTTP.Port)) - if common.CheckErr(err, "gin server run") { + if err != nil { + common.Log.Error("gin start http server", err) + os.Exit(1) } }