Changing the logging to use the logger package to be consistent.

This commit is contained in:
Aditya Kalro
2026-02-22 19:10:25 -08:00
parent 81234f7e54
commit 91eff9b34c
+7 -7
View File
@@ -9,7 +9,6 @@ import (
"context" "context"
"database/sql" "database/sql"
"fmt" "fmt"
"log"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@@ -26,6 +25,7 @@ import (
"github.com/sipeed/picoclaw/pkg/bus" "github.com/sipeed/picoclaw/pkg/bus"
"github.com/sipeed/picoclaw/pkg/config" "github.com/sipeed/picoclaw/pkg/config"
"github.com/sipeed/picoclaw/pkg/logger"
"github.com/sipeed/picoclaw/pkg/utils" "github.com/sipeed/picoclaw/pkg/utils"
"go.mau.fi/whatsmeow/proto/waE2E" "go.mau.fi/whatsmeow/proto/waE2E"
@@ -62,7 +62,7 @@ func NewWhatsAppNativeChannel(cfg config.WhatsAppConfig, bus *bus.MessageBus, st
} }
func (c *WhatsAppNativeChannel) Start(ctx context.Context) error { func (c *WhatsAppNativeChannel) Start(ctx context.Context) error {
log.Printf("Starting WhatsApp native channel (whatsmeow), store: %s", c.storePath) logger.InfoCF("channels", "Starting WhatsApp native channel (whatsmeow)", map[string]any{"store": c.storePath})
if err := os.MkdirAll(c.storePath, 0700); err != nil { if err := os.MkdirAll(c.storePath, 0700); err != nil {
return fmt.Errorf("create session store dir: %w", err) return fmt.Errorf("create session store dir: %w", err)
@@ -116,14 +116,14 @@ func (c *WhatsAppNativeChannel) Start(ctx context.Context) error {
} }
for evt := range qrChan { for evt := range qrChan {
if evt.Event == "code" { if evt.Event == "code" {
log.Println("Scan this QR code with WhatsApp (Linked Devices):") logger.InfoCF("channels", "Scan this QR code with WhatsApp (Linked Devices):", nil)
qrterminal.GenerateWithConfig(evt.Code, qrterminal.Config{ qrterminal.GenerateWithConfig(evt.Code, qrterminal.Config{
Level: qrterminal.L, Level: qrterminal.L,
Writer: os.Stdout, Writer: os.Stdout,
HalfBlocks: true, HalfBlocks: true,
}) })
} else { } else {
log.Printf("WhatsApp login event: %s", evt.Event) logger.InfoCF("channels", "WhatsApp login event", map[string]any{"event": evt.Event})
} }
} }
} else { } else {
@@ -134,12 +134,12 @@ func (c *WhatsAppNativeChannel) Start(ctx context.Context) error {
} }
c.setRunning(true) c.setRunning(true)
log.Println("WhatsApp native channel connected") logger.InfoCF("channels", "WhatsApp native channel connected", nil)
return nil return nil
} }
func (c *WhatsAppNativeChannel) Stop(ctx context.Context) error { func (c *WhatsAppNativeChannel) Stop(ctx context.Context) error {
log.Println("Stopping WhatsApp native channel...") logger.InfoCF("channels", "Stopping WhatsApp native channel", nil)
c.mu.Lock() c.mu.Lock()
client := c.client client := c.client
container := c.container container := c.container
@@ -195,7 +195,7 @@ func (c *WhatsAppNativeChannel) handleIncoming(evt *events.Message) {
metadata["peer_id"] = senderID metadata["peer_id"] = senderID
} }
log.Printf("WhatsApp message from %s: %s...", senderID, utils.Truncate(content, 50)) logger.InfoCF("channels", "WhatsApp message received", map[string]any{"sender_id": senderID, "content_preview": utils.Truncate(content, 50)})
c.HandleMessage(senderID, chatID, content, mediaPaths, metadata) c.HandleMessage(senderID, chatID, content, mediaPaths, metadata)
} }