diff --git a/config/config.go b/config/config.go index 34b4402..1a6d974 100644 --- a/config/config.go +++ b/config/config.go @@ -5,7 +5,6 @@ import ( "strings" "git.sr.ht/~cco/go-scopes/lib" - "git.sr.ht/~cco/go-scopes/lib/core" ) type Cfg struct { @@ -40,16 +39,10 @@ func (cfg *base) Starter() lib.StartProc { } func (cfg *base) Step() lib.StepProc { - if cfg.step == nil { - return core.Step - } return cfg.step } func (cfg *base) MessageHandler() lib.MessageHandler { - if cfg.msgHandler == nil { - return core.HandleMessage - } return cfg.msgHandler } @@ -86,12 +79,18 @@ func (cfg *base) AddAction(pattern string, specs ...lib.ActionSpec) lib.Config { func Base(name string, starter lib.StartProc) *base { return &base{ - name: name, - starter: starter, - actions: nil, + name: name, + starter: starter, + step: Step, + msgHandler: MsgHandler, + actions: nil, } } +// will be set by core.init() +var Step lib.StepProc +var MsgHandler lib.MessageHandler + // action configuration type action struct { diff --git a/lib/action/action.go b/lib/action/action.go index fe959e8..ee27d20 100644 --- a/lib/action/action.go +++ b/lib/action/action.go @@ -5,6 +5,7 @@ import ( "git.sr.ht/~cco/go-scopes/lib" "git.sr.ht/~cco/go-scopes/lib/message" + "git.sr.ht/~cco/go-scopes/logging/log" ) type BaseSpec = baseSpec @@ -43,6 +44,8 @@ func Select(ctx lib.Context, msg lib.Message) []lib.Action { func match(ac lib.ActionConfig, msg lib.Message) bool { fmt.Println("action.match", ac.Pattern(), msg.Action()) + log.Debug().Str("pattern", ac.Pattern()).Str("action", msg.Action()). + Msg("action.match") return ac.Pattern() == msg.Action() //return false } diff --git a/lib/core/core.go b/lib/core/core.go index 5d2eed2..4dcbbab 100644 --- a/lib/core/core.go +++ b/lib/core/core.go @@ -3,6 +3,7 @@ package core import ( "fmt" + "git.sr.ht/~cco/go-scopes/config" "git.sr.ht/~cco/go-scopes/lib" "git.sr.ht/~cco/go-scopes/lib/action" ) @@ -38,3 +39,8 @@ func HandleMessage(ctx lib.Context, msg lib.Message) (loop bool) { } return } + +func init() { + config.Step = Step // avoid import cycle + config.MsgHandler = HandleMessage +} diff --git a/logging/logging.go b/logging/logging.go index de5a09c..b847dd3 100644 --- a/logging/logging.go +++ b/logging/logging.go @@ -53,10 +53,15 @@ func New(cfg *Cfg, home string) (*Logger, error) { GetLogger(nil).Err(err).Msg("logging.New: open log file") return nil, err } - lc := zerolog.New(f).With().Timestamp() - // TODO: evaluate cfg.Level - // lc.Level(level) - logger := lc.Logger() + logger := zerolog.New(f).With().Timestamp().Logger() + if cfg.Level != "" { + if lvl, ok := Levels[cfg.Level]; ok { + logger = logger.Level(lvl) + } else { + GetLogger(nil).Warn().Str("level", cfg.Level). + Msg("logging.New: undefined level") + } + } return &logger, nil }