mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-26 21:05:30 +00:00
add a logging processor
This commit is contained in:
29
internal/processing/debug-log.go
Normal file
29
internal/processing/debug-log.go
Normal 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
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
5
route.go
5
route.go
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user