logging set-up basically working
This commit is contained in:
parent
fe4cdbb3b8
commit
2295213a4a
4 changed files with 17 additions and 15 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
bin*
|
||||
scopes.log
|
||||
|
|
|
@ -25,30 +25,35 @@ func Setup(ctx lib.Context, cfg *Cfg, home string) {
|
|||
if cfg == nil {
|
||||
return // use unchanged predefined logger
|
||||
}
|
||||
if logger, err := New(cfg, home); err != nil {
|
||||
//panic(err)
|
||||
logger.Err(err)
|
||||
//GetLogger(nil).Err(err)
|
||||
} else {
|
||||
*globalLogger = logger
|
||||
}
|
||||
}
|
||||
|
||||
func New(cfg *Cfg, home string) (Logger, error) {
|
||||
home, _ = filepath.Abs(home)
|
||||
fn := cfg.Logfile
|
||||
// TODO: use: logger := New(cfg, home)
|
||||
if fn == "" {
|
||||
fn = filepath.Join(home, "log", "scopes.log")
|
||||
} else if !filepath.IsAbs(fn) {
|
||||
fn = filepath.Join(home, fn)
|
||||
}
|
||||
fmt.Println("logfile:", fn)
|
||||
if f, err := os.OpenFile(fn, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0664); err == nil {
|
||||
logger := zerolog.New(f).With().Timestamp().Logger()
|
||||
*globalLogger = logger
|
||||
} else {
|
||||
panic(err)
|
||||
f, err := os.OpenFile(fn, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0664)
|
||||
if err != nil {
|
||||
return *globalLogger, err
|
||||
}
|
||||
}
|
||||
|
||||
func New(cfg *Cfg, home string) *Logger {
|
||||
return nil
|
||||
return zerolog.New(f).With().Timestamp().Logger(), nil
|
||||
}
|
||||
|
||||
func GetLogger(ctx lib.Context) *Logger {
|
||||
if ctx == nil {
|
||||
return globalLogger
|
||||
}
|
||||
// return ctx.Logger()
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
{"level":"info","service":"config","time":"2023-06-26T10:21:47+02:00","message":"started"}
|
||||
{"level":"info","service":"test-receiver","time":"2023-06-26T10:21:47+02:00","message":"started"}
|
||||
{"level":"info","service":"config","time":"2023-06-26T10:28:53+02:00","message":"started"}
|
||||
{"level":"info","service":"test-receiver","time":"2023-06-26T10:28:53+02:00","message":"started"}
|
|
@ -28,7 +28,7 @@ func ConfigTest(t *testing.T) {
|
|||
cfg := etc.Config()
|
||||
t.AssertEqual(cfg.Name(), "testing")
|
||||
appCfg := cfg.(*app.Cfg)
|
||||
t.AssertEqual(appCfg.Home, "tests")
|
||||
t.AssertEqual(appCfg.Home, ".")
|
||||
confCtx := t.Ctx.Services()["config"]
|
||||
t.AssertEqual(confCtx.Config().Name(), "config")
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue