From ffbf4341fa2b3c786ea9805c21f4f59ad93ce81f Mon Sep 17 00:00:00 2001 From: Stefan Koelle Date: Sun, 9 Aug 2026 21:46:25 +0200 Subject: [PATCH] Remove debug output from TUI, use verbose-only logging for tmux setup - Debug fmt.Fprintf calls were always visible in TUI - Added VerboseLog() to kubeexec package for use by full.go - All tmux debug output now only shows with --verbose flag --- cmd/kctl-tui/full.go | 9 +++++---- internal/kubeexec/log.go | 10 ++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cmd/kctl-tui/full.go b/cmd/kctl-tui/full.go index b56d8da..481d47d 100644 --- a/cmd/kctl-tui/full.go +++ b/cmd/kctl-tui/full.go @@ -280,8 +280,9 @@ func (m *fullModel) startTmuxSession() tea.Cmd { ctxA := m.cfg.ResolveContext(envA, m.selectedContext) k9sCmdA := fmt.Sprintf("k9s --context %s -n %s", ctxA, m.selectedNamespace) - fmt.Fprintf(os.Stderr, "[debug] selfPath=%s\n", selfPath) - fmt.Fprintf(os.Stderr, "[debug] panelCmd=%s\n", panelCmd) + kubeexec.VerboseLog("[debug] selfPath=%s\n", selfPath) + kubeexec.VerboseLog("[debug] panelCmd=%s\n", panelCmd) + kubeexec.VerboseLog("[debug] k9sCmdA=%s\n", k9sCmdA) // Kill stale session first (ignore error if none exists). exec.Command("tmux", "kill-session", "-t", "kctl").Run() @@ -297,6 +298,7 @@ func (m *fullModel) startTmuxSession() tea.Cmd { envB := m.cfg.Envs[1] ctxB := m.cfg.ResolveContext(envB, m.selectedContext) k9sCmdB := fmt.Sprintf("k9s --context %s -n %s", ctxB, m.selectedNamespace) + kubeexec.VerboseLog("[debug] k9sCmdB=%s\n", k9sCmdB) setup = append(setup, []string{"split-window", "-v", "-t", "kctl:0.1", k9sCmdB}) } setup = append(setup, @@ -306,13 +308,12 @@ func (m *fullModel) startTmuxSession() tea.Cmd { for _, args := range setup { if out, err := exec.Command("tmux", args...).CombinedOutput(); err != nil { - fmt.Fprintf(os.Stderr, "[debug] tmux %s failed: %v\n%s\n", args[0], err, out) + kubeexec.VerboseLog("[debug] tmux %s failed: %v\n%s\n", args[0], err, out) return func() tea.Msg { return tmuxDoneMsg{err: fmt.Errorf("tmux %s: %w", args[0], err)} } } } // Only attach uses tea.ExecProcess so it takes over the terminal. - fmt.Fprintf(os.Stderr, "[debug] tmux attach -t kctl\n") c := exec.Command("tmux", "attach", "-t", "kctl") return tea.ExecProcess(c, func(err error) tea.Msg { return tmuxDoneMsg{err: err} diff --git a/internal/kubeexec/log.go b/internal/kubeexec/log.go index 448692f..49e9278 100644 --- a/internal/kubeexec/log.go +++ b/internal/kubeexec/log.go @@ -29,6 +29,16 @@ func SetVerbose(enabled bool, w io.Writer) { } } +// VerboseLog writes a message to the verbose log if enabled. +func VerboseLog(format string, args ...interface{}) { + mu.Lock() + defer mu.Unlock() + if !verbose { + return + } + fmt.Fprintf(logOut, format, args...) +} + func logCmd(name string, args ...string) { mu.Lock() defer mu.Unlock()