uniform logging

This commit is contained in:
Ettore Di Giacinto
2024-04-19 00:02:00 +02:00
parent 2cba2eafe6
commit 08563c3286
13 changed files with 178 additions and 108 deletions

View File

@@ -3,10 +3,11 @@ package connector
import (
"fmt"
"log"
"log/slog"
"os"
"strings"
"github.com/mudler/local-agent-framework/xlog"
"github.com/mudler/local-agent-framework/agent"
"github.com/slack-go/slack/socketmode"
@@ -61,11 +62,11 @@ func (t *Slack) Start(a *agent.Agent) {
for evt := range client.Events {
switch evt.Type {
case socketmode.EventTypeConnecting:
slog.Info("Connecting to Slack with Socket Mode...")
xlog.Info("Connecting to Slack with Socket Mode...")
case socketmode.EventTypeConnectionError:
slog.Info("Connection failed. Retrying later...")
xlog.Info("Connection failed. Retrying later...")
case socketmode.EventTypeConnected:
slog.Info("Connected to Slack with Socket Mode.")
xlog.Info("Connected to Slack with Socket Mode.")
case socketmode.EventTypeEventsAPI:
eventsAPIEvent, ok := evt.Data.(slackevents.EventsAPIEvent)
if !ok {
@@ -92,7 +93,7 @@ func (t *Slack) Start(a *agent.Agent) {
if t.channelID == "" && !t.alwaysReply || // If we have set alwaysReply and no channelID
t.channelID != ev.Channel { // If we have a channelID and it's not the same as the event channel
// Skip messages from other channels
slog.Info("Skipping reply to channel", ev.Channel, t.channelID)
xlog.Info("Skipping reply to channel", ev.Channel, t.channelID)
continue
}
@@ -124,7 +125,7 @@ func (t *Slack) Start(a *agent.Agent) {
// strip our id from the message
message = strings.ReplaceAll(message, "<@"+b.UserID+"> ", "")
slog.Info("Message", message)
xlog.Info("Message", message)
go func() {
res := a.Ask(