Documentation
¶
Overview ¶
Package output provides user-facing output and file logging.
Index ¶
- Variables
- func GetLogFilePath() string
- func GetPanicLogPath() string
- func LogPanic(panicValue any, stack string)
- type ConsoleOutput
- func (c *ConsoleOutput) Debug(format string, args ...any)
- func (c *ConsoleOutput) DirectiveCD(path string)
- func (c *ConsoleOutput) DirectiveRerun(args ...string)
- func (c *ConsoleOutput) Error(format string, args ...any)
- func (c *ConsoleOutput) Info(format string, args ...any)
- func (c *ConsoleOutput) IsQuiet() bool
- func (c *ConsoleOutput) Newline()
- func (c *ConsoleOutput) Print(content string)
- func (c *ConsoleOutput) Println(content string)
- func (c *ConsoleOutput) SetQuiet(quiet bool)
- func (c *ConsoleOutput) Success(format string, args ...any)
- func (c *ConsoleOutput) Tip(format string, args ...any)
- func (c *ConsoleOutput) Warn(format string, args ...any)
- type FileLogger
- func (l *FileLogger) Close() error
- func (l *FileLogger) Debug(msg string, args ...any)
- func (l *FileLogger) Error(msg string, args ...any)
- func (l *FileLogger) Info(msg string, args ...any)
- func (l *FileLogger) Trace(op string, durationMicros int64, success bool, err error, attrs ...slog.Attr)
- func (l *FileLogger) Warn(msg string, args ...any)
- type Logger
- type NullLogger
- type NullOutput
- func (n *NullOutput) Debug(_ string, _ ...any)
- func (n *NullOutput) DirectiveCD(_ string)
- func (n *NullOutput) DirectiveRerun(_ ...string)
- func (n *NullOutput) Error(_ string, _ ...any)
- func (n *NullOutput) Info(_ string, _ ...any)
- func (n *NullOutput) IsQuiet() bool
- func (n *NullOutput) Newline()
- func (n *NullOutput) Print(_ string)
- func (n *NullOutput) Println(_ string)
- func (n *NullOutput) SetQuiet(_ bool)
- func (n *NullOutput) Success(_ string, _ ...any)
- func (n *NullOutput) Tip(_ string, _ ...any)
- func (n *NullOutput) Warn(_ string, _ ...any)
- type Output
- type TestOutput
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultConsoleWriter is the writer used when no writer is specified. // This can be overridden in tests to capture output. DefaultConsoleWriter io.Writer = os.Stdout )
Functions ¶
func GetLogFilePath ¶
func GetLogFilePath() string
GetLogFilePath returns the path to the log file. If STACKIT_LOG_FILE is set, uses that path. Otherwise, uses ~/.stackit/logs/stackit.log
func GetPanicLogPath ¶
func GetPanicLogPath() string
GetPanicLogPath returns the path to the panic log file. This is a dedicated file for panic/crash information that is separate from regular logs to ensure panics are always findable. Uses ~/.stackit/logs/panic.log
Types ¶
type ConsoleOutput ¶
type ConsoleOutput struct {
// contains filtered or unexported fields
}
ConsoleOutput implements Output for terminal output.
func NewConsoleOutput ¶
func NewConsoleOutput(writer io.Writer, debugMode bool) *ConsoleOutput
NewConsoleOutput creates a new console output writer.
func NewDefaultOutput ¶
func NewDefaultOutput() *ConsoleOutput
NewDefaultOutput creates a console output with stdout and debug from env.
func (*ConsoleOutput) Debug ¶
func (c *ConsoleOutput) Debug(format string, args ...any)
Debug writes a debug message (only if debug mode is enabled).
func (*ConsoleOutput) DirectiveCD ¶
func (c *ConsoleOutput) DirectiveCD(path string)
DirectiveCD outputs a shell integration directive for changing directory. This is always output (even in quiet mode) as the shell wrapper needs to parse it. If STACKIT_DIRECTIVE_FILE is set, writes to that file instead of stdout.
func (*ConsoleOutput) DirectiveRerun ¶
func (c *ConsoleOutput) DirectiveRerun(args ...string)
DirectiveRerun outputs a shell integration directive to run a command after cd. If args are provided, runs "stackit <args...>". Otherwise re-runs the original command. This is always output (even in quiet mode) as the shell wrapper needs to parse it. If STACKIT_DIRECTIVE_FILE is set, writes to that file instead of stdout.
func (*ConsoleOutput) Error ¶
func (c *ConsoleOutput) Error(format string, args ...any)
Error writes an error message with emoji prefix.
func (*ConsoleOutput) Info ¶
func (c *ConsoleOutput) Info(format string, args ...any)
Info writes an info message.
func (*ConsoleOutput) IsQuiet ¶
func (c *ConsoleOutput) IsQuiet() bool
IsQuiet returns whether quiet mode is enabled.
func (*ConsoleOutput) Print ¶
func (c *ConsoleOutput) Print(content string)
Print writes raw content without a newline.
func (*ConsoleOutput) Println ¶
func (c *ConsoleOutput) Println(content string)
Println writes content with a newline.
func (*ConsoleOutput) SetQuiet ¶
func (c *ConsoleOutput) SetQuiet(quiet bool)
SetQuiet enables or disables quiet mode.
func (*ConsoleOutput) Success ¶
func (c *ConsoleOutput) Success(format string, args ...any)
Success writes a success message with emoji prefix.
func (*ConsoleOutput) Tip ¶
func (c *ConsoleOutput) Tip(format string, args ...any)
Tip writes a tip message with emoji prefix.
func (*ConsoleOutput) Warn ¶
func (c *ConsoleOutput) Warn(format string, args ...any)
Warn writes a warning message with emoji prefix.
type FileLogger ¶
type FileLogger struct {
// contains filtered or unexported fields
}
FileLogger implements Logger with file-based structured logging.
func NewFileLogger ¶
func NewFileLogger(logFilePath string) (*FileLogger, error)
NewFileLogger creates a logger that writes to the specified file with rotation.
func (*FileLogger) Debug ¶
func (l *FileLogger) Debug(msg string, args ...any)
Debug logs a debug message.
func (*FileLogger) Error ¶
func (l *FileLogger) Error(msg string, args ...any)
Error logs an error message.
func (*FileLogger) Info ¶
func (l *FileLogger) Info(msg string, args ...any)
Info logs an info message.
func (*FileLogger) Trace ¶
func (l *FileLogger) Trace(op string, durationMicros int64, success bool, err error, attrs ...slog.Attr)
Trace logs a structured operation trace at DEBUG level. This is optimized to minimize allocations by using slog's native attribute handling.
func (*FileLogger) Warn ¶
func (l *FileLogger) Warn(msg string, args ...any)
Warn logs a warning message.
type Logger ¶
type Logger interface {
Debug(msg string, args ...any)
Info(msg string, args ...any)
Warn(msg string, args ...any)
Error(msg string, args ...any)
Trace(op string, durationMicros int64, success bool, err error, attrs ...slog.Attr)
Close() error
}
Logger handles persistent file logging for debugging.
func NewFileLoggerOrNull ¶
NewFileLoggerOrNull creates a FileLogger, falling back to NullLogger on error. This is useful for contexts where logging is optional (e.g., crash handlers).
type NullLogger ¶
type NullLogger struct{}
NullLogger discards all log messages.
func NewNullLogger ¶
func NewNullLogger() *NullLogger
NewNullLogger creates a logger that discards all output.
func (*NullLogger) Debug ¶
func (l *NullLogger) Debug(_ string, _ ...any)
Debug discards the message.
func (*NullLogger) Error ¶
func (l *NullLogger) Error(_ string, _ ...any)
Error discards the message.
type NullOutput ¶
type NullOutput struct{}
NullOutput discards all output (for quiet tests).
func NewNullOutput ¶
func NewNullOutput() *NullOutput
NewNullOutput creates an output that discards everything.
func (*NullOutput) Debug ¶
func (n *NullOutput) Debug(_ string, _ ...any)
Debug discards the message.
func (*NullOutput) DirectiveCD ¶
func (n *NullOutput) DirectiveCD(_ string)
DirectiveCD discards the directive.
func (*NullOutput) DirectiveRerun ¶
func (n *NullOutput) DirectiveRerun(_ ...string)
DirectiveRerun discards the directive.
func (*NullOutput) Error ¶
func (n *NullOutput) Error(_ string, _ ...any)
Error discards the message.
func (*NullOutput) Success ¶
func (n *NullOutput) Success(_ string, _ ...any)
Success discards the message.
type Output ¶
type Output interface {
// Leveled messages with prefixes
Info(format string, args ...any)
Warn(format string, args ...any)
Error(format string, args ...any)
Tip(format string, args ...any)
Success(format string, args ...any)
Debug(format string, args ...any) // Only shown with debug flag
// Raw output (no formatting)
Print(content string)
Println(content string)
Newline()
// Shell integration directives (always output, parsed by shell wrapper)
DirectiveCD(path string) // Output __STACKIT_CD__:<path> for shell integration
DirectiveRerun(args ...string) // Output __STACKIT_RERUN__[:args] to run command after cd
// Quiet mode for TUI coordination
SetQuiet(quiet bool)
IsQuiet() bool
}
Output handles user-facing console messages.
type TestOutput ¶
type TestOutput struct {
*ConsoleOutput
// contains filtered or unexported fields
}
TestOutput captures output for testing assertions.
func NewTestOutput ¶
func NewTestOutput() *TestOutput
NewTestOutput creates an output that captures all messages for testing.
func (*TestOutput) Bytes ¶
func (t *TestOutput) Bytes() []byte
Bytes returns all captured output as bytes.
func (*TestOutput) String ¶
func (t *TestOutput) String() string
String returns all captured output as a string.