remove all print statemens - use log.Debug() (or Info()) where appropriate

This commit is contained in:
Helmut Merz 2023-06-27 10:19:13 +02:00
parent e063bb1b03
commit 9dc12deb19
5 changed files with 9 additions and 21 deletions

View file

@ -1,7 +1,6 @@
package app package app
import ( import (
"fmt"
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
@ -29,10 +28,8 @@ func start(ctx lib.Context) {
for _, cfg := range ctx.Config().Children() { for _, cfg := range ctx.Config().Children() {
cctx := ctx.ChildContext(cfg) cctx := ctx.ChildContext(cfg)
cfg.Starter()(cctx) cfg.Starter()(cctx)
fmt.Println(cfg.Name(), " started")
log.Info().Str("service", cfg.Name()).Msg("started")
} }
fmt.Println("running ", ctx.WaitGroup()) log.Info().Msg("app.start: running")
sig := make(chan os.Signal, 1) sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM) signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
for step(ctx, sig) { for step(ctx, sig) {
@ -42,14 +39,12 @@ func start(ctx lib.Context) {
func step(ctx lib.Context, sig <-chan os.Signal) bool { func step(ctx lib.Context, sig <-chan os.Signal) bool {
select { select {
case <-sig: case <-sig:
fmt.Println("interrupted") log.Info().Msg("app.step: interrupted")
//ctx.LogInfo("Dispatcher interrupted", m.Map{})
return false return false
case msg := <-ctx.Mailbox(): case msg := <-ctx.Mailbox():
fmt.Println("app.step: message =", msg) //log.Debug().Str("msg.action", msg.Action()).Msg("app.step: message")
//ctx.LogDebug("dispatcherStep", m.Map{"msg": msg})
if msg == message.Quit { if msg == message.Quit {
//ctx.LogInfo("Dispatcher stopped", m.Map{}) log.Info().Msg("app.step: stopped")
return false return false
} }
return lib.HandleMsg(ctx, msg) return lib.HandleMsg(ctx, msg)

View file

@ -1,8 +1,6 @@
package action package action
import ( import (
"fmt"
"git.sr.ht/~cco/go-scopes/lib" "git.sr.ht/~cco/go-scopes/lib"
"git.sr.ht/~cco/go-scopes/lib/message" "git.sr.ht/~cco/go-scopes/lib/message"
"git.sr.ht/~cco/go-scopes/logging/log" "git.sr.ht/~cco/go-scopes/logging/log"
@ -43,8 +41,7 @@ func Select(ctx lib.Context, msg lib.Message) []lib.Action {
} }
func match(ac lib.ActionConfig, msg lib.Message) bool { func match(ac lib.ActionConfig, msg lib.Message) bool {
fmt.Println("action.match", ac.Pattern(), msg.Action()) log.Debug().Str("pattern", ac.Pattern()).Str("msg.action", msg.Action()).
log.Debug().Str("pattern", ac.Pattern()).Str("action", msg.Action()).
Msg("action.match") Msg("action.match")
return ac.Pattern() == msg.Action() return ac.Pattern() == msg.Action()
//return false //return false

View file

@ -1,15 +1,14 @@
package core package core
import ( import (
"fmt"
"git.sr.ht/~cco/go-scopes/config" "git.sr.ht/~cco/go-scopes/config"
"git.sr.ht/~cco/go-scopes/lib" "git.sr.ht/~cco/go-scopes/lib"
"git.sr.ht/~cco/go-scopes/lib/action" "git.sr.ht/~cco/go-scopes/lib/action"
"git.sr.ht/~cco/go-scopes/logging/log"
) )
func Start(ctx lib.Context) { func Start(ctx lib.Context) {
fmt.Println("Start:", ctx.Config().Name()) log.Debug().Str("service", ctx.Config().Name()).Msg("core.Start")
lib.RunCtx(ctx, Listen) lib.RunCtx(ctx, Listen)
} }
@ -33,7 +32,8 @@ func Step(ctx lib.Context) (loop bool) {
func HandleMessage(ctx lib.Context, msg lib.Message) (loop bool) { func HandleMessage(ctx lib.Context, msg lib.Message) (loop bool) {
loop = true loop = true
fmt.Println("core.HandleMessage", ctx.Config().Name(), msg) log.Debug().Str("service", ctx.Config().Name()).Str("msg.action", msg.Action()).
Msg("core.HandleMessage")
for _, act := range action.Select(ctx, msg) { for _, act := range action.Select(ctx, msg) {
loop = act.Handle() loop = act.Handle()
} }

View file

@ -3,7 +3,6 @@
package testing package testing
import ( import (
"fmt"
"regexp" "regexp"
"testing" "testing"
"time" "time"
@ -54,7 +53,6 @@ func (t *T) TearDownApp() {
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
//t.Check() //t.Check()
message.SimpleAddress("testing").Send(t.Ctx, message.Quit) message.SimpleAddress("testing").Send(t.Ctx, message.Quit)
fmt.Println("teardown ", t.Ctx.WaitGroup())
t.Ctx.WaitGroup().Wait() t.Ctx.WaitGroup().Wait()
//t.AssertNoUncheckedMessages() //t.AssertNoUncheckedMessages()
} }

View file

@ -1,7 +1,6 @@
package scopes_test package scopes_test
import ( import (
"fmt"
"os" "os"
tbase "testing" tbase "testing"
@ -47,7 +46,6 @@ func SendTest(t *testing.T) {
func Receiver(act lib.Action) bool { func Receiver(act lib.Action) bool {
// t := testing.GetT(act.Context()) // t := testing.GetT(act.Context())
t := act.Context().Parent().State().(*testing.T) t := act.Context().Parent().State().(*testing.T)
fmt.Println("test.Receiver:", act.Message().Action())
t.AssertEqual(act.Message().Action(), "demo") t.AssertEqual(act.Message().Action(), "demo")
return true return true
} }