mirror of
https://github.com/skoelle/kctl-tui.git
synced 2026-09-17 20:10:24 +00:00
- 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
70 lines
1.3 KiB
Go
70 lines
1.3 KiB
Go
// Copyright (c) 2026 Stefan Koelle (https://stefankoelle.de)
|
|
// Licensed under the MIT License. See LICENSE file in project root for details.
|
|
|
|
package kubeexec
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
"sync"
|
|
)
|
|
|
|
var (
|
|
verbose bool
|
|
logOut io.Writer = io.Discard
|
|
mu sync.Mutex
|
|
)
|
|
|
|
// SetVerbose enables or disables debug logging of executed commands.
|
|
// When enabled, commands and their outputs are written to the provided
|
|
// writer (typically os.Stderr). When disabled (the default), all logging
|
|
// is discarded.
|
|
func SetVerbose(enabled bool, w io.Writer) {
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
verbose = enabled
|
|
if w != nil {
|
|
logOut = w
|
|
}
|
|
}
|
|
|
|
// 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()
|
|
if !verbose {
|
|
return
|
|
}
|
|
fmt.Fprintf(logOut, "[cmd] %s %s\n", name, strings.Join(args, " "))
|
|
}
|
|
|
|
func logOutput(name string, output string) {
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
if !verbose {
|
|
return
|
|
}
|
|
if output != "" {
|
|
fmt.Fprintf(logOut, "[out] %s: %s\n", name, output)
|
|
}
|
|
}
|
|
|
|
func logErr(name string, err error) {
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
if !verbose {
|
|
return
|
|
}
|
|
fmt.Fprintf(logOut, "[err] %s: %v\n", name, err)
|
|
}
|