add a logging processor

This commit is contained in:
Joel Wetzell
2025-11-22 16:59:16 -06:00
parent 7bc7087ffe
commit fdefad44ab
2 changed files with 29 additions and 5 deletions

View File

@@ -0,0 +1,29 @@
package processing
import (
"context"
"fmt"
"log/slog"
)
type DebugLog struct {
config ProcessorConfig
}
func (dl *DebugLog) Process(ctx context.Context, payload any) (any, error) {
slog.Debug("debug.log", "payload", payload, "payloadType", fmt.Sprintf("%T", payload))
return payload, nil
}
func (dl *DebugLog) Type() string {
return dl.config.Type
}
func init() {
RegisterProcessor(ProcessorRegistration{
Type: "debug.log",
New: func(config ProcessorConfig) (Processor, error) {
return &DebugLog{config: config}, nil
},
})
}

View File

@@ -2,7 +2,6 @@ package showbridge
import ( import (
"fmt" "fmt"
"log/slog"
"github.com/jwetzell/showbridge-go/internal/processing" "github.com/jwetzell/showbridge-go/internal/processing"
) )
@@ -49,9 +48,6 @@ func NewRoute(index int, config RouteConfig, router *Router) (*Route, error) {
} }
func (r *Route) HandleInput(sourceId string, payload any) error { func (r *Route) HandleInput(sourceId string, payload any) error {
slog.Debug("route input", "index", r.index, "source", sourceId, "payload", payload)
slog.Debug("route processing", "processorCount", len(r.Processors))
var err error var err error
for _, processor := range r.Processors { for _, processor := range r.Processors {
payload, err = processor.Process(r.router.Context, payload) payload, err = processor.Process(r.router.Context, payload)
@@ -67,6 +63,5 @@ func (r *Route) HandleInput(sourceId string, payload any) error {
} }
func (r *Route) HandleOutput(payload any) error { func (r *Route) HandleOutput(payload any) error {
slog.Debug("route output", "index", r.index, "destination", r.Output, "payload", payload)
return r.router.HandleOutput(r.Output, payload) return r.router.HandleOutput(r.Output, payload)
} }