work in progress: logging - set up log config workflow for testing and main

This commit is contained in:
Helmut Merz 2023-06-08 16:50:52 +02:00
parent e66b1c0364
commit 3455b409fb
12 changed files with 68 additions and 5 deletions

View file

@ -9,6 +9,7 @@ import (
"git.sr.ht/~cco/go-scopes/config"
"git.sr.ht/~cco/go-scopes/lib"
"git.sr.ht/~cco/go-scopes/lib/message"
"git.sr.ht/~cco/go-scopes/logging"
"git.sr.ht/~cco/go-scopes/logging/log"
)
@ -16,6 +17,7 @@ type Cfg struct {
*config.Base
AppType string
Home string
Logging *logging.Config
}
func Start(ctx lib.Context) {

View file

@ -4,6 +4,7 @@ import (
"git.sr.ht/~cco/go-scopes/app"
"git.sr.ht/~cco/go-scopes/config"
"git.sr.ht/~cco/go-scopes/lib"
"git.sr.ht/~cco/go-scopes/logging"
)
func Config() lib.Config {
@ -13,6 +14,9 @@ func Config() lib.Config {
Base: b("dummy", app.Start),
Home: ovr(".", HOME),
AppType: "standard",
Logging: &logging.Config{
Logfile: ovr("log/scopes.log", LOGFILE),
},
}
cfg.Add(config.Cfg{
Base: b("config", config.Start),
@ -24,5 +28,6 @@ func Config() lib.Config {
// collect here the names of fields that may be overridden via
// explicit Override() or SCOPES_* environment settings.
const (
HOME = "home"
HOME = "home"
LOGFILE = "logfile"
)

View file

@ -4,4 +4,11 @@ go 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

19
examples/demo/go.sum Normal file
View 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=

View file

@ -0,0 +1 @@
Directory `log`. Store log files here.

View file

@ -7,6 +7,7 @@ import (
"git.sr.ht/~cco/go-scopes"
"git.sr.ht/~cco/go-scopes/app"
"git.sr.ht/~cco/go-scopes/logging"
)
func main() {
@ -14,5 +15,6 @@ func main() {
fmt.Println(cfg.Name())
appCfg := cfg.(*app.Cfg)
fmt.Println(appCfg.Home)
logging.Setup(appCfg.Logging, appCfg.Home)
scopes.RunApp(cfg)
}

View file

@ -23,9 +23,9 @@ type Config interface {
Step() StepProc
MessageHandler() MessageHandler
Actions() []ActionConfig
AddAction(string, ActionSpec)
Children() []Config
Add(Config)
AddAction(string, ActionSpec)
}
type Services map[string]Context

View file

@ -1,5 +1,5 @@
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

View file

@ -1 +1,19 @@
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)
}
}

View file

@ -12,6 +12,7 @@ import (
"git.sr.ht/~cco/go-scopes/lib"
"git.sr.ht/~cco/go-scopes/lib/context"
"git.sr.ht/~cco/go-scopes/lib/message"
"git.sr.ht/~cco/go-scopes/logging"
)
func Start(ctx lib.Context) {
@ -39,6 +40,8 @@ func SetUp(tbase *testing.T) *T {
}
func SetUpApp(tbase *testing.T, cfg lib.Config) *T {
appCfg := cfg.(*app.Cfg)
logging.Setup(appCfg.Logging, appCfg.Home)
t := SetUp(tbase)
t.Ctx = context.AppContext(cfg).WithState(t)
cfg.Starter()(t.Ctx)

View file

@ -6,6 +6,7 @@ import (
"git.sr.ht/~cco/go-scopes/lib"
"git.sr.ht/~cco/go-scopes/lib/action"
"git.sr.ht/~cco/go-scopes/lib/core"
"git.sr.ht/~cco/go-scopes/logging"
"git.sr.ht/~cco/go-scopes/testing"
)
@ -17,6 +18,9 @@ func Config() lib.Config {
Base: b("testing", testing.Start),
Home: ovr(".", HOME),
AppType: "standard",
Logging: &logging.Config{
Logfile: ovr("log/scopes.log", LOGFILE),
},
}
cfg.AddAction("demo",
action.BaseSpec(action.Forward,
@ -43,7 +47,8 @@ var (
// collect here the names of fields that may be overridden via
// explicit Override() or SCOPES_* environment settings.
const (
HOME = "home"
HOME = "home"
LOGFILE = "logfile"
)
// in a production scenario this should be put in a separate

1
tests/log/README.md Normal file
View file

@ -0,0 +1 @@
Directory `log`. Store log files here.