From 1dc8d6346e548e5e1b6a78aeaea91eb96fba37cc Mon Sep 17 00:00:00 2001 From: "Noah.Martin" <1066840101@qq.com> Date: Thu, 11 Apr 2024 13:38:48 +0800 Subject: [PATCH] -- FIX - Remove useless log - Set logger color --- main.go | 3 ++- util/ai_util/openai_image.go | 6 ++++-- util/http_util/httpUtil.go | 9 +++++---- util/math_engine/math.go | 4 ++-- util/top_list/daily_record.go | 12 ++++++------ 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/main.go b/main.go index c75eb3d..d1e19d5 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "github.com/NoahAmethyst/go-cqhttp/cmd/gocq" "github.com/NoahAmethyst/go-cqhttp/util/cron" "github.com/NoahAmethyst/go-cqhttp/util/top_list" + "github.com/sirupsen/logrus" "time" _ "github.com/NoahAmethyst/go-cqhttp/db/leveldb" // leveldb @@ -18,7 +19,7 @@ import ( func main() { var cstZone = time.FixedZone("CST", 8*3600) // 东八 time.Local = cstZone - + logrus.SetFormatter(&logrus.TextFormatter{ForceColors: true}) // Initialize grpc client for _, rpcCli := range rpc.RpcCliList { rpc.InitGrpcCli(rpcCli) diff --git a/util/ai_util/openai_image.go b/util/ai_util/openai_image.go index 549a281..42db228 100644 --- a/util/ai_util/openai_image.go +++ b/util/ai_util/openai_image.go @@ -2,8 +2,8 @@ package ai_util import ( "context" - "github.com/rs/zerolog/log" "github.com/sashabaranov/go-openai" + log "github.com/sirupsen/logrus" ) func GenerateImage(prompt, size string) (*openai.ImageResponse, error) { @@ -21,6 +21,8 @@ func GenerateImage(prompt, size string) (*openai.ImageResponse, error) { User: "", }, ) - log.Info().Msgf("收到openai响应:%+v", resp) + + log.Infof("receive openai response:%+v", resp) + return &resp, err } diff --git a/util/http_util/httpUtil.go b/util/http_util/httpUtil.go index 58256d9..4bd2bbe 100644 --- a/util/http_util/httpUtil.go +++ b/util/http_util/httpUtil.go @@ -4,7 +4,7 @@ import ( "bytes" "encoding/json" "github.com/pkg/errors" - "github.com/rs/zerolog/log" + log "github.com/sirupsen/logrus" "io" "io/ioutil" @@ -107,7 +107,7 @@ func PostJSON(url string, params interface{}, headers map[string]string, ret int b, err := Post(url, params, headers) if err != nil { - log.Err(err) + log.Error(err) return err } @@ -143,11 +143,12 @@ func PostForm(thisUrl string, params map[string]string, headers map[string]strin if err != nil { return err } - log.Info().Fields(map[string]interface{}{ + + log.Infof("%+v", map[string]interface{}{ "action": "post form", "url": thisUrl, "response": result, - }).Send() + }) return err } diff --git a/util/math_engine/math.go b/util/math_engine/math.go index dc581e1..4b93417 100644 --- a/util/math_engine/math.go +++ b/util/math_engine/math.go @@ -2,7 +2,7 @@ package math_engine import ( "github.com/dengsgo/math-engine/engine" - "github.com/rs/zerolog/log" + log "github.com/sirupsen/logrus" "strings" ) @@ -32,7 +32,7 @@ func Calculate(expression string) (float64, error) { r, err := engine.ParseAndExec(expression) if err != nil { - log.Err(err) + log.Error(err) } return r, err } diff --git a/util/top_list/daily_record.go b/util/top_list/daily_record.go index b088a34..f5f96e9 100644 --- a/util/top_list/daily_record.go +++ b/util/top_list/daily_record.go @@ -91,7 +91,7 @@ func (d *d36KrDailyRecord) Load() { func (d *d36KrDailyRecord) Backup() { d.RLock() defer d.RUnlock() - log.Infof("backup 36kr daily record") + //log.Infof("backup 36kr daily record") path := file_util.GetFileRoot() _, _ = file_util.WriteJsonFile(d.data, path, "36kr", true) @@ -160,7 +160,7 @@ func (d *wallStreetNewsDailyRecord) Load() { func (d *wallStreetNewsDailyRecord) Backup() { d.RLock() defer d.RUnlock() - log.Infof("backup wallstreet news daily record") + //log.Infof("backup wallstreet news daily record") path := file_util.GetFileRoot() _, _ = file_util.WriteJsonFile(d.data, path, "wallstreet_news", true) } @@ -228,7 +228,7 @@ func (d *caixinnewsDailyRecord) Load() { func (d *caixinnewsDailyRecord) Backup() { d.RLock() defer d.RUnlock() - log.Infof("backup caixin news daily record") + //log.Infof("backup caixin news daily record") path := file_util.GetFileRoot() _, _ = file_util.WriteJsonFile(d.data, path, "caixin_news", true) } @@ -296,7 +296,7 @@ func (d *weiboHotDailyRecord) Load() { func (d *weiboHotDailyRecord) Backup() { d.RLock() defer d.RUnlock() - log.Infof("backup weibo hot daily record") + //log.Infof("backup weibo hot daily record") path := file_util.GetFileRoot() _, _ = file_util.WriteJsonFile(d.data, path, "weibo_hot", true) } @@ -365,7 +365,7 @@ func (z *zhihuHotDailyRecord) Load() { func (d *zhihuHotDailyRecord) Backup() { d.RLock() defer d.RUnlock() - log.Infof("backup zhihu hot daily record") + //log.Infof("backup zhihu hot daily record") path := file_util.GetFileRoot() _, _ = file_util.WriteJsonFile(d.data, path, "zhihu", true) } @@ -433,7 +433,7 @@ func (z *sentCache) Load() { func (d *sentCache) Backup() { d.RLock() defer d.RUnlock() - log.Infof("backup sent news cache") + //log.Infof("backup sent news cache") path := file_util.GetFileRoot() _, _ = file_util.WriteJsonFile(d.data, path, "sentNews", true) }