work in progress: logging

This commit is contained in:
Helmut Merz 2023-06-14 19:20:16 +02:00
parent 3455b409fb
commit 2141e41241
5 changed files with 31 additions and 4 deletions

View file

@ -4,11 +4,13 @@ import (
"sync" "sync"
"git.sr.ht/~cco/go-scopes/lib" "git.sr.ht/~cco/go-scopes/lib"
"git.sr.ht/~cco/go-scopes/logging"
) )
type appContext struct { type appContext struct {
*context *context
services Services services Services
logger *logging.Logger
waitgroup *sync.WaitGroup waitgroup *sync.WaitGroup
doneCh chan struct{} doneCh chan struct{}
} }

9
lib/system/system.go Normal file
View file

@ -0,0 +1,9 @@
package system
import "git.sr.ht/~cco/go-scopes/lib"
func RemoveFile(ctx lib.Context, fpath string) {
}
func RemoveFiles(ctx lib.Context, path, pattern string) {
}

View file

@ -2,4 +2,4 @@ package log
import "git.sr.ht/~cco/go-scopes/logging" import "git.sr.ht/~cco/go-scopes/logging"
var Info = logging.Logger.Info var Info = logging.GetLogger(nil).Info

View file

@ -3,17 +3,33 @@ package logging
import ( import (
"fmt" "fmt"
"git.sr.ht/~cco/go-scopes/lib"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
) )
var Logger = log.Logger type Logger = zerolog.Logger
var globalLogger Logger = log.Logger
type Config struct { type Config struct {
Logfile string Logfile string
Level zerolog.Level
} }
func Setup(cfg *Config, home string) { func Setup(ctx lib.Context, cfg *Config, home string) {
if cfg != nil { if cfg != nil {
fmt.Println("logging:", home, cfg.Logfile) fmt.Println("logging:", home, cfg.Logfile)
} }
} }
func New(cfg *Config, home string) *Logger {
return nil
}
func GetLogger(ctx lib.Context) *zerolog.Logger {
if ctx == nil {
return &globalLogger
}
return nil
}

View file

@ -41,9 +41,9 @@ 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) 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)
logging.Setup(t.Ctx, appCfg.Logging, appCfg.Home)
cfg.Starter()(t.Ctx) cfg.Starter()(t.Ctx)
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
return t return t