fayec/extensions/debug.go
2023-09-18 21:01:38 -05:00

32 lines
621 B
Go

package extensions
import (
"encoding/json"
"gitea.watsonlabs.net/watsonb8/fayec/message"
"io"
"log"
)
func debugJson(v interface{}) string {
b, _ := json.MarshalIndent(v, "", " ")
return string(b)
}
type DebugExtension struct {
in *log.Logger
out *log.Logger
}
func NewDebugExtension(out io.Writer) *DebugExtension {
li := log.New(out, "InMsg", 0)
lo := log.New(out, "OutMsg", 0)
return &DebugExtension{in: li, out: lo}
}
func (d *DebugExtension) InExtension(m *message.Message) {
d.in.Println(debugJson(m))
}
func (d *DebugExtension) OutExtension(m *message.Message) {
d.out.Println(debugJson(m))
}