diff --git a/examples/bytes/dequeue/bytes.go b/examples/bytes/dequeue/bytes.go index 30487d2..312b63f 100644 --- a/examples/bytes/dequeue/bytes.go +++ b/examples/bytes/dequeue/bytes.go @@ -10,24 +10,16 @@ package main import ( "log/slog" - "os" "github.com/fogfish/swarm" "github.com/fogfish/swarm/broker/sqs" + "github.com/fogfish/swarm/internal/qtest" "github.com/fogfish/swarm/queue" "github.com/fogfish/swarm/queue/bytes" ) func main() { - slog.SetDefault( - slog.New( - slog.NewTextHandler(os.Stdout, - &slog.HandlerOptions{ - Level: slog.LevelDebug, - }, - ), - ), - ) + qtest.NewLogger() q := queue.Must(sqs.New("swarm-test", swarm.WithLogStdErr())) diff --git a/examples/bytes/enqueue/bytes.go b/examples/bytes/enqueue/bytes.go index 8a97a9b..1c8c2fe 100644 --- a/examples/bytes/enqueue/bytes.go +++ b/examples/bytes/enqueue/bytes.go @@ -9,25 +9,15 @@ package main import ( - "log/slog" - "os" - "github.com/fogfish/swarm" "github.com/fogfish/swarm/broker/sqs" + "github.com/fogfish/swarm/internal/qtest" "github.com/fogfish/swarm/queue" "github.com/fogfish/swarm/queue/bytes" ) func main() { - slog.SetDefault( - slog.New( - slog.NewTextHandler(os.Stdout, - &slog.HandlerOptions{ - Level: slog.LevelDebug, - }, - ), - ), - ) + qtest.NewLogger() q := queue.Must(sqs.New("swarm-test", swarm.WithLogStdErr())) diff --git a/examples/eventbridge/dequeue/eventbridge.go b/examples/eventbridge/dequeue/eventbridge.go index 4c0a583..39d883e 100644 --- a/examples/eventbridge/dequeue/eventbridge.go +++ b/examples/eventbridge/dequeue/eventbridge.go @@ -13,6 +13,7 @@ import ( "github.com/fogfish/swarm" "github.com/fogfish/swarm/broker/eventbridge" + "github.com/fogfish/swarm/internal/qtest" "github.com/fogfish/swarm/queue" ) @@ -32,6 +33,8 @@ type Like struct { } func main() { + qtest.NewLogger() + q := queue.Must(eventbridge.New("swarm-example-eventbridge", swarm.WithLogStdErr())) go actor[User]("user").handle(queue.Dequeue[User](q)) diff --git a/examples/eventbridge/enqueue/eventbridge.go b/examples/eventbridge/enqueue/eventbridge.go index 9ec030a..4020196 100644 --- a/examples/eventbridge/enqueue/eventbridge.go +++ b/examples/eventbridge/enqueue/eventbridge.go @@ -11,6 +11,7 @@ package main import ( "github.com/fogfish/swarm" "github.com/fogfish/swarm/broker/eventbridge" + "github.com/fogfish/swarm/internal/qtest" "github.com/fogfish/swarm/queue" ) @@ -30,6 +31,8 @@ type Like struct { } func main() { + qtest.NewLogger() + q := queue.Must(eventbridge.New("swarm-example-eventbridge-latest", swarm.WithSource("swarm-example-eventbridge"), swarm.WithLogStdErr(), diff --git a/examples/events/dequeue/events.go b/examples/events/dequeue/events.go index 5392289..7ad3f32 100644 --- a/examples/events/dequeue/events.go +++ b/examples/events/dequeue/events.go @@ -14,6 +14,7 @@ import ( "github.com/fogfish/swarm" "github.com/fogfish/swarm/broker/sqs" + "github.com/fogfish/swarm/internal/qtest" "github.com/fogfish/swarm/queue" "github.com/fogfish/swarm/queue/events" ) @@ -51,6 +52,8 @@ func (EventNote) HKT1(swarm.EventType) {} func (EventNote) HKT2(*Note) {} func main() { + qtest.NewLogger() + q := queue.Must(sqs.New("swarm-test", swarm.WithLogStdErr())) go create(events.Dequeue[*User, EventCreateUser](q)) diff --git a/examples/events/enqueue/events.go b/examples/events/enqueue/events.go index b5ff66c..322253c 100644 --- a/examples/events/enqueue/events.go +++ b/examples/events/enqueue/events.go @@ -11,6 +11,7 @@ package main import ( "github.com/fogfish/swarm" "github.com/fogfish/swarm/broker/sqs" + "github.com/fogfish/swarm/internal/qtest" "github.com/fogfish/swarm/queue" "github.com/fogfish/swarm/queue/events" ) @@ -47,6 +48,8 @@ func (EventNote) HKT1(swarm.EventType) {} func (EventNote) HKT2(*Note) {} func main() { + qtest.NewLogger() + q := queue.Must(sqs.New("swarm-test", swarm.WithLogStdErr())) userCreated := swarm.LogDeadLetters(events.Enqueue[*User, EventCreateUser](q)) diff --git a/examples/events3/dequeue/events3.go b/examples/events3/dequeue/events3.go index 50386cf..bc4178a 100644 --- a/examples/events3/dequeue/events3.go +++ b/examples/events3/dequeue/events3.go @@ -14,10 +14,13 @@ import ( "github.com/fogfish/swarm" "github.com/fogfish/swarm/broker/events3" + "github.com/fogfish/swarm/internal/qtest" "github.com/fogfish/swarm/queue" ) func main() { + qtest.NewLogger() + q := queue.Must(events3.New("swarm-test", swarm.WithLogStdErr())) go common(events3.Dequeue(q)) diff --git a/examples/eventsqs/dequeue/eventsqs.go b/examples/eventsqs/dequeue/eventsqs.go index 62e507b..9694095 100644 --- a/examples/eventsqs/dequeue/eventsqs.go +++ b/examples/eventsqs/dequeue/eventsqs.go @@ -13,6 +13,7 @@ import ( "github.com/fogfish/swarm" "github.com/fogfish/swarm/broker/eventsqs" + "github.com/fogfish/swarm/internal/qtest" "github.com/fogfish/swarm/queue" ) @@ -32,6 +33,8 @@ type Like struct { } func main() { + qtest.NewLogger() + q := queue.Must(eventsqs.New("swarm-example-sqs-latest", swarm.WithLogStdErr())) go actor[User]("user").handle(queue.Dequeue[User](q)) diff --git a/examples/eventsqs/enqueue/eventsqs.go b/examples/eventsqs/enqueue/eventsqs.go index 51c527f..e3201cb 100644 --- a/examples/eventsqs/enqueue/eventsqs.go +++ b/examples/eventsqs/enqueue/eventsqs.go @@ -11,6 +11,7 @@ package main import ( "github.com/fogfish/swarm" "github.com/fogfish/swarm/broker/eventsqs" + "github.com/fogfish/swarm/internal/qtest" "github.com/fogfish/swarm/queue" ) @@ -30,6 +31,8 @@ type Like struct { } func main() { + qtest.NewLogger() + q := queue.Must(eventsqs.New("swarm-example-sqs-latest", swarm.WithLogStdErr())) user, _ := queue.Enqueue[*User](q) diff --git a/examples/sqs/dequeue/sqs.go b/examples/sqs/dequeue/sqs.go index 292eb5a..d33e9ad 100644 --- a/examples/sqs/dequeue/sqs.go +++ b/examples/sqs/dequeue/sqs.go @@ -10,10 +10,10 @@ package main import ( "log/slog" - "os" "github.com/fogfish/swarm" "github.com/fogfish/swarm/broker/sqs" + "github.com/fogfish/swarm/internal/qtest" "github.com/fogfish/swarm/queue" ) @@ -33,15 +33,7 @@ type Like struct { } func main() { - slog.SetDefault( - slog.New( - slog.NewTextHandler(os.Stdout, - &slog.HandlerOptions{ - Level: slog.LevelDebug, - }, - ), - ), - ) + qtest.NewLogger() q := queue.Must(sqs.New("swarm-test", swarm.WithLogStdErr())) diff --git a/examples/sqs/enqueue/sqs.go b/examples/sqs/enqueue/sqs.go index f69a990..c68dc30 100644 --- a/examples/sqs/enqueue/sqs.go +++ b/examples/sqs/enqueue/sqs.go @@ -9,11 +9,9 @@ package main import ( - "log/slog" - "os" - "github.com/fogfish/swarm" "github.com/fogfish/swarm/broker/sqs" + "github.com/fogfish/swarm/internal/qtest" "github.com/fogfish/swarm/queue" ) @@ -33,15 +31,7 @@ type Like struct { } func main() { - slog.SetDefault( - slog.New( - slog.NewTextHandler(os.Stdout, - &slog.HandlerOptions{ - Level: slog.LevelDebug, - }, - ), - ), - ) + qtest.NewLogger() q := queue.Must(sqs.New("swarm-test", swarm.WithLogStdErr())) diff --git a/internal/qtest/logger.go b/internal/qtest/logger.go new file mode 100644 index 0000000..de1388f --- /dev/null +++ b/internal/qtest/logger.go @@ -0,0 +1,19 @@ +package qtest + +import ( + "log/slog" + "os" +) + +// Config logger for debug/testing purposes +func NewLogger() { + slog.SetDefault( + slog.New( + slog.NewTextHandler(os.Stdout, + &slog.HandlerOptions{ + Level: slog.LevelDebug, + }, + ), + ), + ) +} diff --git a/queue/bytes/dequeue.go b/queue/bytes/dequeue.go index c8f428f..a67e083 100644 --- a/queue/bytes/dequeue.go +++ b/queue/bytes/dequeue.go @@ -35,7 +35,7 @@ func Dequeue(q swarm.Broker, cat string) (<-chan *swarm.Msg[[]byte], chan<- *swa return } - slog.Debug("Broker ack'ed object", "kind", "bytes", "category", cat, "object", object) + slog.Debug("Broker ack'ed object", "kind", "bytes", "category", cat, "object", object.Object) }) pipe.Emit(ch.Msg, q.Config().PollFrequency, func() (*swarm.Msg[[]byte], error) {