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*
|
bin*
|
||||||
|
scopes.log
|
||||||
|
|
|
@ -25,30 +25,35 @@ func Setup(ctx lib.Context, cfg *Cfg, home string) {
|
||||||
if cfg == nil {
|
if cfg == nil {
|
||||||
return // use unchanged predefined logger
|
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)
|
home, _ = filepath.Abs(home)
|
||||||
fn := cfg.Logfile
|
fn := cfg.Logfile
|
||||||
// TODO: use: logger := New(cfg, home)
|
|
||||||
if fn == "" {
|
if fn == "" {
|
||||||
fn = filepath.Join(home, "log", "scopes.log")
|
fn = filepath.Join(home, "log", "scopes.log")
|
||||||
} else if !filepath.IsAbs(fn) {
|
} else if !filepath.IsAbs(fn) {
|
||||||
fn = filepath.Join(home, fn)
|
fn = filepath.Join(home, fn)
|
||||||
}
|
}
|
||||||
fmt.Println("logfile:", fn)
|
fmt.Println("logfile:", fn)
|
||||||
if f, err := os.OpenFile(fn, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0664); err == nil {
|
f, err := os.OpenFile(fn, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0664)
|
||||||
logger := zerolog.New(f).With().Timestamp().Logger()
|
if err != nil {
|
||||||
*globalLogger = logger
|
return *globalLogger, err
|
||||||
} else {
|
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
}
|
return zerolog.New(f).With().Timestamp().Logger(), nil
|
||||||
|
|
||||||
func New(cfg *Cfg, home string) *Logger {
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetLogger(ctx lib.Context) *Logger {
|
func GetLogger(ctx lib.Context) *Logger {
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
return globalLogger
|
return globalLogger
|
||||||
}
|
}
|
||||||
|
// return ctx.Logger()
|
||||||
return nil
|
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()
|
cfg := etc.Config()
|
||||||
t.AssertEqual(cfg.Name(), "testing")
|
t.AssertEqual(cfg.Name(), "testing")
|
||||||
appCfg := cfg.(*app.Cfg)
|
appCfg := cfg.(*app.Cfg)
|
||||||
t.AssertEqual(appCfg.Home, "tests")
|
t.AssertEqual(appCfg.Home, ".")
|
||||||
confCtx := t.Ctx.Services()["config"]
|
confCtx := t.Ctx.Services()["config"]
|
||||||
t.AssertEqual(confCtx.Config().Name(), "config")
|
t.AssertEqual(confCtx.Config().Name(), "config")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue