Mqtt logging
Some checks failed
CI / Test (1.22) (push) Failing after -23m38s
CI / Test (1.23) (push) Failing after -23m28s
CI / Build (push) Successful in -25m46s
CI / Lint (push) Successful in -25m30s

This commit is contained in:
2025-12-30 00:19:49 +02:00
parent eb788f903a
commit 7b2390cbf6
2 changed files with 4 additions and 1 deletions

View File

@@ -73,6 +73,7 @@ func NewLogger(cfg config.EventLoggerConfig, dbConfig config.DatabaseConfig, waM
logging.Info("Event logger PostgreSQL target initialized") logging.Info("Event logger PostgreSQL target initialized")
case "mqtt": case "mqtt":
logging.Info("Initializing MQTT event logger target", "broker", cfg.MQTT.Broker)
mqttTarget, err := NewMQTTTarget(cfg.MQTT, waManager) mqttTarget, err := NewMQTTTarget(cfg.MQTT, waManager)
if err != nil { if err != nil {
logging.Error("Failed to initialize MQTT target", "error", err) logging.Error("Failed to initialize MQTT target", "error", err)

View File

@@ -82,16 +82,18 @@ func NewMQTTTarget(cfg config.MQTTConfig, waManager WhatsAppManager) (*MQTTTarge
if cfg.Subscribe { if cfg.Subscribe {
// Subscribe to send command topic for all accounts // Subscribe to send command topic for all accounts
topic := fmt.Sprintf("%s/+/send", cfg.TopicPrefix) topic := fmt.Sprintf("%s/+/send", cfg.TopicPrefix)
logging.Info("Starting MQTT subscription", "topic", topic, "qos", cfg.QoS)
if token := client.Subscribe(topic, byte(cfg.QoS), target.handleSendMessage); token.Wait() && token.Error() != nil { if token := client.Subscribe(topic, byte(cfg.QoS), target.handleSendMessage); token.Wait() && token.Error() != nil {
logging.Error("Failed to subscribe to MQTT topic", "topic", topic, "error", token.Error()) logging.Error("Failed to subscribe to MQTT topic", "topic", topic, "error", token.Error())
} else { } else {
logging.Info("Subscribed to MQTT send topic", "topic", topic) logging.Info("Successfully subscribed to MQTT send topic", "topic", topic)
} }
} }
}) })
// Create and connect the client // Create and connect the client
client := mqtt.NewClient(opts) client := mqtt.NewClient(opts)
logging.Info("Starting MQTT connection", "broker", cfg.Broker, "client_id", cfg.ClientID)
if token := client.Connect(); token.Wait() && token.Error() != nil { if token := client.Connect(); token.Wait() && token.Error() != nil {
return nil, fmt.Errorf("failed to connect to MQTT broker: %w", token.Error()) return nil, fmt.Errorf("failed to connect to MQTT broker: %w", token.Error())
} }