feat(tui): move logging to server logs

This commit is contained in:
adamdottv
2025-07-09 08:16:10 -05:00
parent 37a86439c4
commit ca8ce88354
19 changed files with 588 additions and 208 deletions

View File

@@ -5,7 +5,6 @@ import (
"encoding/json"
"log/slog"
"os"
"path/filepath"
"strings"
tea "github.com/charmbracelet/bubbletea/v2"
@@ -15,6 +14,7 @@ import (
"github.com/sst/opencode/internal/app"
"github.com/sst/opencode/internal/clipboard"
"github.com/sst/opencode/internal/tui"
"github.com/sst/opencode/internal/util"
)
var Version = "dev"
@@ -39,33 +39,15 @@ func main() {
os.Exit(1)
}
logfile := filepath.Join(appInfo.Path.Data, "log", "tui.log")
if _, err := os.Stat(filepath.Dir(logfile)); os.IsNotExist(err) {
err := os.MkdirAll(filepath.Dir(logfile), 0755)
if err != nil {
slog.Error("Failed to create log directory", "error", err)
os.Exit(1)
}
}
file, err := os.Create(logfile)
if err != nil {
slog.Error("Failed to create log file", "error", err)
os.Exit(1)
}
defer file.Close()
logger := slog.New(slog.NewTextHandler(file, &slog.HandlerOptions{Level: slog.LevelDebug}))
slog.SetDefault(logger)
slog.Debug("TUI launched", "app", appInfo)
httpClient := opencode.NewClient(
option.WithBaseURL(url),
)
if err != nil {
slog.Error("Failed to create client", "error", err)
os.Exit(1)
}
apiHandler := util.NewAPILogHandler(httpClient, "tui", slog.LevelDebug)
logger := slog.New(apiHandler)
slog.SetDefault(logger)
slog.Debug("TUI launched", "app", appInfo)
go func() {
err = clipboard.Init()