From 5f63a202b4385ce46c735670cf7e083c94ba39a9 Mon Sep 17 00:00:00 2001 From: wood chen Date: Fri, 20 Sep 2024 16:04:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=94=99=E8=AF=AF=E6=97=A5?= =?UTF-8?q?=E5=BF=97=E8=AE=B0=E5=BD=95=E5=92=8C=E9=93=BE=E6=8E=A5=E8=BF=87?= =?UTF-8?q?=E6=BB=A4=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在Binance服务中,增强错误日志记录,提供更详细的上下文信息,包括完整的消息内容和聊天ID,以便更快地诊断问题。 在链接过滤服务中,实现更清晰的日志输出,突出显示新发现的非白名单链接,并直接在检查和过滤过程中记录,提高可读性和效率。 --- service/binance/binance.go | 2 +- service/link_filter/link_filter.go | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/service/binance/binance.go b/service/binance/binance.go index f88d26b..1479606 100644 --- a/service/binance/binance.go +++ b/service/binance/binance.go @@ -101,7 +101,7 @@ func sendPriceUpdate() { msg.ParseMode = "Markdown" sentMsg, err := bot.Send(msg) if err != nil { - log.Printf("Failed to send message: %v", err) + log.Printf("Failed to send message. Error: %v\nFull message content:\nChat ID: %d\nMessage: %s", err, chatID, message) return } diff --git a/service/link_filter/link_filter.go b/service/link_filter/link_filter.go index 8330f8c..cd64b53 100644 --- a/service/link_filter/link_filter.go +++ b/service/link_filter/link_filter.go @@ -186,14 +186,17 @@ func processLinks(links []string, linkFilter *LinkFilter) (bool, []string) { } } - if len(newNonWhitelistedLinks) > 0 { - logger.Printf("发现新的非白名单链接: %v", newNonWhitelistedLinks) - } return false, newNonWhitelistedLinks } func (lf *LinkFilter) CheckAndFilterLink(bot *tgbotapi.BotAPI, message *tgbotapi.Message) bool { // 判断消息是否应当被过滤及找出新的非白名单链接 shouldFilter, newLinks := ShouldFilter(message.Text, lf) + + // 如果发现新的非白名单链接,记录日志 + if len(newLinks) > 0 { + logger.Printf("发现新的非白名单链接: %v", newLinks) + } + if shouldFilter { // 记录被过滤的消息 logger.Printf("消息应该被过滤: %s", message.Text) @@ -218,11 +221,5 @@ func (lf *LinkFilter) CheckAndFilterLink(bot *tgbotapi.BotAPI, message *tgbotapi return true } - // 如果发现新的非白名单链接 - if len(newLinks) > 0 { - // 记录新的非白名单链接 - logger.Printf("发现新的非白名单链接: %v", newLinks) - } - return false }