From 1bc587c20c6ebb80430e84a42054ad11a2b700bc Mon Sep 17 00:00:00 2001 From: simulot Date: Fri, 31 May 2024 21:48:40 +0200 Subject: [PATCH] better log handler initialisation --- cmd/shared.go | 9 +++++++-- cmd/upload/page.go | 5 ++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/cmd/shared.go b/cmd/shared.go index 59919b66..d84a537d 100644 --- a/cmd/shared.go +++ b/cmd/shared.go @@ -100,8 +100,7 @@ func (app *SharedFlags) Start(ctx context.Context) error { if err != nil { return err } - app.Log = slog.New(humane.NewHandler(f, &humane.Options{Level: app.Level})) - app.Jnl.SetLogger(app.Log) + app.SetLogWriter(f) app.LogWriterCloser = f } } @@ -176,3 +175,9 @@ func (app *SharedFlags) Start(ctx context.Context) error { } return nil } + +func (app *SharedFlags) SetLogWriter(w io.Writer) { + app.Log = slog.New(humane.NewHandler(w, &humane.Options{Level: app.Level})) + // app.Log = slog.New(slog.NewJSONHandler(w, &slog.HandlerOptions{})) + app.Jnl.SetLogger(app.Log) +} diff --git a/cmd/upload/page.go b/cmd/upload/page.go index a1b76623..e524fc75 100644 --- a/cmd/upload/page.go +++ b/cmd/upload/page.go @@ -10,7 +10,6 @@ import ( "github.com/navidys/tvxwidgets" "github.com/rivo/tview" "github.com/simulot/immich-go/helpers/fileevent" - "github.com/telemachus/humane" ) type page struct { @@ -88,9 +87,9 @@ func (p *page) Page() *tview.Application { if p.app.SharedFlags.LogWriterCloser != nil { w := io.MultiWriter(p.app.SharedFlags.LogWriterCloser, p.logView) - p.app.SharedFlags.Log = slog.New(humane.NewHandler(w, &humane.Options{Level: p.app.SharedFlags.Level})) + p.app.SetLogWriter(w) } else { - p.app.SharedFlags.Log = slog.New(humane.NewHandler(p.logView, &humane.Options{Level: p.app.SharedFlags.Level})) + p.app.SetLogWriter(p.logView) } p.app.SharedFlags.Jnl.SetLogger(p.app.SharedFlags.Log) p.logView.SetBorder(true).SetTitle("Log")