diff options
| author | Kujtim Hoxha <[email protected]> | 2025-04-10 13:29:44 +0200 |
|---|---|---|
| committer | Kujtim Hoxha <[email protected]> | 2025-04-10 13:29:44 +0200 |
| commit | 36f201d5d3aaba7e0285d86cf1c0cf6b54769cff (patch) | |
| tree | 1f1c99e66df4c25f816fbfba2b1e255c94bec9ba /cmd | |
| parent | 0b007b9c77bc790127021a7e03c8e05ec8e5e081 (diff) | |
| download | opencode-36f201d5d3aaba7e0285d86cf1c0cf6b54769cff.tar.gz opencode-36f201d5d3aaba7e0285d86cf1c0cf6b54769cff.zip | |
fix logs and add cancellation
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/root.go | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/cmd/root.go b/cmd/root.go index c4e99985a..bd9336fce 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -2,6 +2,7 @@ package cmd import ( "context" + "log/slog" "os" "sync" @@ -10,6 +11,7 @@ import ( "github.com/kujtimiihoxha/termai/internal/config" "github.com/kujtimiihoxha/termai/internal/db" "github.com/kujtimiihoxha/termai/internal/llm/agent" + "github.com/kujtimiihoxha/termai/internal/logging" "github.com/kujtimiihoxha/termai/internal/tui" zone "github.com/lrstanley/bubblezone" "github.com/spf13/cobra" @@ -26,6 +28,16 @@ var rootCmd = &cobra.Command{ } debug, _ := cmd.Flags().GetBool("debug") err := config.Load(debug) + cfg := config.Get() + defaultLevel := slog.LevelInfo + if cfg.Debug { + defaultLevel = slog.LevelDebug + } + logger := slog.New(slog.NewTextHandler(logging.NewWriter(), &slog.HandlerOptions{ + Level: defaultLevel, + })) + slog.SetDefault(logger) + if err != nil { return err } @@ -37,14 +49,14 @@ var rootCmd = &cobra.Command{ app := app.New(ctx, conn) defer app.Close() - app.Logger.Info("Starting termai...") + logging.Info("Starting termai...") zone.NewGlobal() tui := tea.NewProgram( tui.New(app), tea.WithAltScreen(), tea.WithMouseCellMotion(), ) - app.Logger.Info("Setting up subscriptions...") + logging.Info("Setting up subscriptions...") ch, unsub := setupSubscriptions(app) defer unsub() @@ -66,9 +78,8 @@ func setupSubscriptions(app *app.App) (chan tea.Msg, func()) { ch := make(chan tea.Msg) wg := sync.WaitGroup{} ctx, cancel := context.WithCancel(app.Context) - { - sub := app.Logger.Subscribe(ctx) + sub := logging.Subscribe(ctx) wg.Add(1) go func() { for ev := range sub { |
