Skip to content

Commit

Permalink
better log handler initialisation
Browse files Browse the repository at this point in the history
  • Loading branch information
simulot committed May 31, 2024
1 parent dc65281 commit 1bc587c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 7 additions & 2 deletions cmd/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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)
}
5 changes: 2 additions & 3 deletions cmd/upload/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 1bc587c

Please sign in to comment.