work in progress: logging - set up log config workflow for testing and main
This commit is contained in:
parent
e66b1c0364
commit
3455b409fb
12 changed files with 68 additions and 5 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"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/message"
|
"git.sr.ht/~cco/go-scopes/lib/message"
|
||||||
|
"git.sr.ht/~cco/go-scopes/logging"
|
||||||
"git.sr.ht/~cco/go-scopes/logging/log"
|
"git.sr.ht/~cco/go-scopes/logging/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -16,6 +17,7 @@ type Cfg struct {
|
||||||
*config.Base
|
*config.Base
|
||||||
AppType string
|
AppType string
|
||||||
Home string
|
Home string
|
||||||
|
Logging *logging.Config
|
||||||
}
|
}
|
||||||
|
|
||||||
func Start(ctx lib.Context) {
|
func Start(ctx lib.Context) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"git.sr.ht/~cco/go-scopes/app"
|
"git.sr.ht/~cco/go-scopes/app"
|
||||||
"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/logging"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Config() lib.Config {
|
func Config() lib.Config {
|
||||||
|
@ -13,6 +14,9 @@ func Config() lib.Config {
|
||||||
Base: b("dummy", app.Start),
|
Base: b("dummy", app.Start),
|
||||||
Home: ovr(".", HOME),
|
Home: ovr(".", HOME),
|
||||||
AppType: "standard",
|
AppType: "standard",
|
||||||
|
Logging: &logging.Config{
|
||||||
|
Logfile: ovr("log/scopes.log", LOGFILE),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
cfg.Add(config.Cfg{
|
cfg.Add(config.Cfg{
|
||||||
Base: b("config", config.Start),
|
Base: b("config", config.Start),
|
||||||
|
@ -24,5 +28,6 @@ func Config() lib.Config {
|
||||||
// collect here the names of fields that may be overridden via
|
// collect here the names of fields that may be overridden via
|
||||||
// explicit Override() or SCOPES_* environment settings.
|
// explicit Override() or SCOPES_* environment settings.
|
||||||
const (
|
const (
|
||||||
HOME = "home"
|
HOME = "home"
|
||||||
|
LOGFILE = "logfile"
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,4 +4,11 @@ go 1.20
|
||||||
|
|
||||||
require git.sr.ht/~cco/go-scopes v0.1.20
|
require git.sr.ht/~cco/go-scopes v0.1.20
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||||
|
github.com/rs/zerolog v1.29.1 // indirect
|
||||||
|
golang.org/x/sys v0.8.0 // indirect
|
||||||
|
)
|
||||||
|
|
||||||
replace git.sr.ht/~cco/go-scopes => ../../../go-scopes
|
replace git.sr.ht/~cco/go-scopes => ../../../go-scopes
|
||||||
|
|
19
examples/demo/go.sum
Normal file
19
examples/demo/go.sum
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||||
|
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
|
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
|
||||||
|
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||||
|
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||||
|
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
|
||||||
|
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
|
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||||
|
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||||
|
github.com/rs/zerolog v1.29.1 h1:cO+d60CHkknCbvzEWxP0S9K6KqyTjrCNUy1LdQLCGPc=
|
||||||
|
github.com/rs/zerolog v1.29.1/go.mod h1:Le6ESbR7hc+DP6Lt1THiV8CQSdkkNrd3R0XbEgp3ZBU=
|
||||||
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
|
||||||
|
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
1
examples/demo/log/README.md
Normal file
1
examples/demo/log/README.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Directory `log`. Store log files here.
|
|
@ -7,6 +7,7 @@ import (
|
||||||
|
|
||||||
"git.sr.ht/~cco/go-scopes"
|
"git.sr.ht/~cco/go-scopes"
|
||||||
"git.sr.ht/~cco/go-scopes/app"
|
"git.sr.ht/~cco/go-scopes/app"
|
||||||
|
"git.sr.ht/~cco/go-scopes/logging"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -14,5 +15,6 @@ func main() {
|
||||||
fmt.Println(cfg.Name())
|
fmt.Println(cfg.Name())
|
||||||
appCfg := cfg.(*app.Cfg)
|
appCfg := cfg.(*app.Cfg)
|
||||||
fmt.Println(appCfg.Home)
|
fmt.Println(appCfg.Home)
|
||||||
|
logging.Setup(appCfg.Logging, appCfg.Home)
|
||||||
scopes.RunApp(cfg)
|
scopes.RunApp(cfg)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,9 @@ type Config interface {
|
||||||
Step() StepProc
|
Step() StepProc
|
||||||
MessageHandler() MessageHandler
|
MessageHandler() MessageHandler
|
||||||
Actions() []ActionConfig
|
Actions() []ActionConfig
|
||||||
|
AddAction(string, ActionSpec)
|
||||||
Children() []Config
|
Children() []Config
|
||||||
Add(Config)
|
Add(Config)
|
||||||
AddAction(string, ActionSpec)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Services map[string]Context
|
type Services map[string]Context
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
package log
|
package log
|
||||||
|
|
||||||
import "github.com/rs/zerolog/log"
|
import "git.sr.ht/~cco/go-scopes/logging"
|
||||||
|
|
||||||
var Info = log.Info
|
var Info = logging.Logger.Info
|
||||||
|
|
|
@ -1 +1,19 @@
|
||||||
package logging
|
package logging
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Logger = log.Logger
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Logfile string
|
||||||
|
}
|
||||||
|
|
||||||
|
func Setup(cfg *Config, home string) {
|
||||||
|
if cfg != nil {
|
||||||
|
fmt.Println("logging:", home, cfg.Logfile)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"git.sr.ht/~cco/go-scopes/lib"
|
"git.sr.ht/~cco/go-scopes/lib"
|
||||||
"git.sr.ht/~cco/go-scopes/lib/context"
|
"git.sr.ht/~cco/go-scopes/lib/context"
|
||||||
"git.sr.ht/~cco/go-scopes/lib/message"
|
"git.sr.ht/~cco/go-scopes/lib/message"
|
||||||
|
"git.sr.ht/~cco/go-scopes/logging"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Start(ctx lib.Context) {
|
func Start(ctx lib.Context) {
|
||||||
|
@ -39,6 +40,8 @@ func SetUp(tbase *testing.T) *T {
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetUpApp(tbase *testing.T, cfg lib.Config) *T {
|
func SetUpApp(tbase *testing.T, cfg lib.Config) *T {
|
||||||
|
appCfg := cfg.(*app.Cfg)
|
||||||
|
logging.Setup(appCfg.Logging, appCfg.Home)
|
||||||
t := SetUp(tbase)
|
t := SetUp(tbase)
|
||||||
t.Ctx = context.AppContext(cfg).WithState(t)
|
t.Ctx = context.AppContext(cfg).WithState(t)
|
||||||
cfg.Starter()(t.Ctx)
|
cfg.Starter()(t.Ctx)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"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/lib/core"
|
"git.sr.ht/~cco/go-scopes/lib/core"
|
||||||
|
"git.sr.ht/~cco/go-scopes/logging"
|
||||||
"git.sr.ht/~cco/go-scopes/testing"
|
"git.sr.ht/~cco/go-scopes/testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -17,6 +18,9 @@ func Config() lib.Config {
|
||||||
Base: b("testing", testing.Start),
|
Base: b("testing", testing.Start),
|
||||||
Home: ovr(".", HOME),
|
Home: ovr(".", HOME),
|
||||||
AppType: "standard",
|
AppType: "standard",
|
||||||
|
Logging: &logging.Config{
|
||||||
|
Logfile: ovr("log/scopes.log", LOGFILE),
|
||||||
|
},
|
||||||
}
|
}
|
||||||
cfg.AddAction("demo",
|
cfg.AddAction("demo",
|
||||||
action.BaseSpec(action.Forward,
|
action.BaseSpec(action.Forward,
|
||||||
|
@ -43,7 +47,8 @@ var (
|
||||||
// collect here the names of fields that may be overridden via
|
// collect here the names of fields that may be overridden via
|
||||||
// explicit Override() or SCOPES_* environment settings.
|
// explicit Override() or SCOPES_* environment settings.
|
||||||
const (
|
const (
|
||||||
HOME = "home"
|
HOME = "home"
|
||||||
|
LOGFILE = "logfile"
|
||||||
)
|
)
|
||||||
|
|
||||||
// in a production scenario this should be put in a separate
|
// in a production scenario this should be put in a separate
|
||||||
|
|
1
tests/log/README.md
Normal file
1
tests/log/README.md
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Directory `log`. Store log files here.
|
Loading…
Add table
Reference in a new issue