fix(qq): demote botgo heartbeat logs
This commit is contained in:
parent
0cbf11ddfa
commit
441116450a
2 changed files with 42 additions and 1 deletions
41
pkg/channels/qq/botgo_logger.go
Normal file
41
pkg/channels/qq/botgo_logger.go
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
package qq
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/sipeed/picoclaw/pkg/logger"
|
||||||
|
)
|
||||||
|
|
||||||
|
// botGoLogger preserves useful SDK info logs while demoting noisy heartbeat
|
||||||
|
// traffic to DEBUG so long-running QQ sessions do not spam the console.
|
||||||
|
type botGoLogger struct {
|
||||||
|
*logger.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
func newBotGoLogger(component string) *botGoLogger {
|
||||||
|
return &botGoLogger{Logger: logger.NewLogger(component)}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *botGoLogger) Info(v ...interface{}) {
|
||||||
|
message := fmt.Sprint(v...)
|
||||||
|
if shouldDemoteBotGoInfo(message) {
|
||||||
|
b.Logger.Debug(message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
b.Logger.Info(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *botGoLogger) Infof(format string, v ...interface{}) {
|
||||||
|
message := fmt.Sprintf(format, v...)
|
||||||
|
if shouldDemoteBotGoInfo(message) {
|
||||||
|
b.Logger.Debug(message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
b.Logger.Info(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
func shouldDemoteBotGoInfo(message string) bool {
|
||||||
|
return strings.Contains(message, " write Heartbeat message") ||
|
||||||
|
strings.Contains(message, " receive HeartbeatAck message")
|
||||||
|
}
|
||||||
|
|
@ -102,7 +102,7 @@ func (c *QQChannel) Start(ctx context.Context) error {
|
||||||
return fmt.Errorf("QQ app_id and app_secret not configured")
|
return fmt.Errorf("QQ app_id and app_secret not configured")
|
||||||
}
|
}
|
||||||
|
|
||||||
botgo.SetLogger(logger.NewLogger("botgo"))
|
botgo.SetLogger(newBotGoLogger("botgo"))
|
||||||
logger.InfoC("qq", "Starting QQ bot (WebSocket mode)")
|
logger.InfoC("qq", "Starting QQ bot (WebSocket mode)")
|
||||||
|
|
||||||
// Reinitialize shutdown signal for clean restart.
|
// Reinitialize shutdown signal for clean restart.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue