Skip to content

Commit

Permalink
set up debug logging for dispatcher matching
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulSonOfLars committed Dec 23, 2024
1 parent f866334 commit 33f6210
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ext/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ import (

func logError(l *slog.Logger, text string, err error) {
if l == nil {
log.Printf("ERROR: %s: %s", text, err)
log.Printf("ERROR: %s: %s", text, err.Error())
return
}
l.Error(text, "error", err)
l.Error(text, "error", err.Error())
}

func logDebug(l *slog.Logger, text string, args ...any) {
if l == nil {
// No logger? No debug.
return
}
l.Error(text, args...)
}

// ternary operator approximation.
Expand Down
4 changes: 4 additions & 0 deletions ext/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,12 @@ func (d *Dispatcher) iterateOverHandlerGroups(b *gotgbot.Bot, ctx *Context) erro
continue
}

logDebug(d.Logger, "Matched handler on update", "handler", handler.Name())

err := handler.HandleUpdate(b, ctx)
if err != nil {
logDebug(d.Logger, "Update handling returned error", "handler", handler.Name(), "error", err.Error())

if errors.Is(err, ContinueGroups) {
// Continue handling current group.
continue
Expand Down

0 comments on commit 33f6210

Please sign in to comment.