Documentation
¶
Overview ¶
Package logger provides logging interfaces and implementations for mooncake.
Index ¶
- Constants
- func GetTerminalSize() (width, height int)
- func IsTUISupported() bool
- func ParseLogLevel(level string) (int, error)
- func StripANSI(s string) string
- func TruncateANSI(s string, maxWidth int) string
- func VisibleLength(s string) int
- type AgentSubscriber
- type AnimationFrames
- type BufferSnapshot
- type ConsoleLogger
- func (l *ConsoleLogger) Codef(format string, v ...interface{})
- func (l *ConsoleLogger) Complete(stats ExecutionStats)
- func (l *ConsoleLogger) Debugf(format string, v ...interface{})
- func (l *ConsoleLogger) Errorf(format string, v ...interface{})
- func (l *ConsoleLogger) Infof(format string, v ...interface{})
- func (l *ConsoleLogger) LogStep(info StepInfo)
- func (l *ConsoleLogger) Mooncake()
- func (l *ConsoleLogger) SetLogLevel(logLevel int)
- func (l *ConsoleLogger) SetLogLevelStr(logLevel string) error
- func (l *ConsoleLogger) SetRedactor(redactor Redactor)
- func (l *ConsoleLogger) Textf(format string, v ...interface{})
- func (l *ConsoleLogger) WithPadLevel(padLevel int) Logger
- type ConsoleSubscriber
- type ExecutionStats
- type LogEntry
- type Logger
- type ProgressInfo
- type QuietSubscriber
- type Redactor
- type RunLogSubscriber
- type StderrErrorSubscriber
- type StepEntry
- type StepInfo
- type TUIBuffer
- func (b *TUIBuffer) AddDebug(message string)
- func (b *TUIBuffer) AddError(message string)
- func (b *TUIBuffer) AddStep(entry StepEntry)
- func (b *TUIBuffer) GetSnapshot() BufferSnapshot
- func (b *TUIBuffer) SetCompletion(stats ExecutionStats)
- func (b *TUIBuffer) SetCurrentStep(name string, progress ProgressInfo)
- type TUIDisplay
- type TUILogger
- func (l *TUILogger) Codef(format string, v ...interface{})
- func (l *TUILogger) Complete(stats ExecutionStats)
- func (l *TUILogger) Debugf(format string, v ...interface{})
- func (l *TUILogger) Errorf(format string, v ...interface{})
- func (l *TUILogger) Infof(_ string, _ ...interface{})
- func (l *TUILogger) LogStep(info StepInfo)
- func (l *TUILogger) Mooncake()
- func (l *TUILogger) SetLogLevel(logLevel int)
- func (l *TUILogger) SetLogLevelStr(logLevel string) error
- func (l *TUILogger) SetRedactor(redactor Redactor)
- func (l *TUILogger) Start()
- func (l *TUILogger) Stop()
- func (l *TUILogger) Textf(format string, v ...interface{})
- func (l *TUILogger) WithPadLevel(padLevel int) Logger
- type TUISubscriber
- type TerminalInfo
- type TestLogger
- func (t *TestLogger) Clear()
- func (t *TestLogger) Codef(format string, v ...interface{})
- func (t *TestLogger) Complete(stats ExecutionStats)
- func (t *TestLogger) Contains(substr string) bool
- func (t *TestLogger) ContainsLevel(level, substr string) bool
- func (t *TestLogger) Count() int
- func (t *TestLogger) CountLevel(level string) int
- func (t *TestLogger) Debugf(format string, v ...interface{})
- func (t *TestLogger) Errorf(format string, v ...interface{})
- func (t *TestLogger) GetLogs() []LogEntry
- func (t *TestLogger) Infof(format string, v ...interface{})
- func (t *TestLogger) LogStep(info StepInfo)
- func (t *TestLogger) Mooncake()
- func (t *TestLogger) SetLogLevel(logLevel int)
- func (t *TestLogger) SetLogLevelStr(logLevel string) error
- func (t *TestLogger) SetRedactor(redactor Redactor)
- func (t *TestLogger) Textf(format string, v ...interface{})
- func (t *TestLogger) WithPadLevel(padLevel int) Logger
Constants ¶
const ( // DebugLevel logs are typically voluminous, and are usually disabled in // production. DebugLevel = iota // InfoLevel is the default logging priority. InfoLevel // ErrorLevel logs are high-priority. If an application is running smoothly, // it shouldn't generate any error-logLevel logs. ErrorLevel )
const ( StatusRunning = "running" StatusSuccess = "success" StatusError = "error" StatusSkipped = "skipped" )
Step status constants used across all logger implementations
Variables ¶
This section is empty.
Functions ¶
func GetTerminalSize ¶
func GetTerminalSize() (width, height int)
GetTerminalSize returns the current terminal size. Returns default 80x24 if detection fails.
func IsTUISupported ¶
func IsTUISupported() bool
IsTUISupported checks if the terminal supports TUI mode. Returns true if terminal is detected, supports ANSI codes, and meets minimum size requirements.
func ParseLogLevel ¶ added in v0.5.0
ParseLogLevel converts a log level string to its integer constant. Valid values are "debug", "info", and "error" (case-insensitive). Returns an error if the level string is not recognized.
func StripANSI ¶ added in v0.5.0
StripANSI removes all ANSI escape codes from a string. This includes color codes, cursor movement, and other terminal control sequences.
Example:
StripANSI("\x1b[31mRed Text\x1b[0m") → "Red Text"
func TruncateANSI ¶ added in v0.5.0
TruncateANSI truncates a string to the specified visible width while preserving ANSI escape codes. If truncation occurs, an ellipsis is added.
The function: 1. Preserves all ANSI codes before the truncation point 2. Counts only visible characters for width calculation 3. Adds "..." when truncation occurs 4. Handles UTF-8 characters correctly
Example:
TruncateANSI("\x1b[31mLong Red Text\x1b[0m", 8) → "\x1b[31mLong...\x1b[0m"
func VisibleLength ¶ added in v0.5.0
VisibleLength returns the number of visible characters in a string, excluding ANSI escape codes.
This properly counts UTF-8 characters (runes) rather than bytes, so emoji and other multi-byte characters count as 1.
Example:
VisibleLength("\x1b[31mRed\x1b[0m") → 3
VisibleLength("Hello 🌙") → 7
Types ¶
type AgentSubscriber ¶ added in v0.5.0
type AgentSubscriber struct{}
AgentSubscriber writes one flat JSON line per lifecycle event to stdout. No ANSI, no human framing — designed for programmatic consumption.
func NewAgentSubscriber ¶ added in v0.5.0
func NewAgentSubscriber() *AgentSubscriber
NewAgentSubscriber creates a new AgentSubscriber.
func (*AgentSubscriber) Close ¶ added in v0.5.0
func (a *AgentSubscriber) Close()
Close implements the Subscriber interface.
func (*AgentSubscriber) OnEvent ¶ added in v0.5.0
func (a *AgentSubscriber) OnEvent(event events.Event)
OnEvent handles an incoming event and writes a JSONL record.
type AnimationFrames ¶
type AnimationFrames struct {
// contains filtered or unexported fields
}
AnimationFrames manages animation frames for the mooncake character.
func LoadEmbeddedFrames ¶
func LoadEmbeddedFrames() (*AnimationFrames, error)
LoadEmbeddedFrames loads animation frames from the embedded content.
func LoadFramesFromFile ¶
func LoadFramesFromFile(path string) (*AnimationFrames, error)
LoadFramesFromFile loads animation frames from a file. Frames are expected to be 3 lines each, separated by blank lines.
func LoadFramesFromString ¶
func LoadFramesFromString(content string) (*AnimationFrames, error)
LoadFramesFromString loads animation frames from a string. Frames are expected to be 3 lines each, separated by blank lines.
func (*AnimationFrames) Current ¶
func (a *AnimationFrames) Current() []string
Current returns the current frame without advancing
func (*AnimationFrames) FrameCount ¶
func (a *AnimationFrames) FrameCount() int
FrameCount returns the total number of frames
func (*AnimationFrames) Next ¶
func (a *AnimationFrames) Next() []string
Next advances to the next frame and returns it
type BufferSnapshot ¶
type BufferSnapshot struct {
StepHistory []StepEntry
CurrentStep string
Progress ProgressInfo
DebugMessages []string
ErrorMessages []string
Completion *ExecutionStats
}
BufferSnapshot is an atomic snapshot of the buffer state for rendering.
type ConsoleLogger ¶
type ConsoleLogger struct {
// contains filtered or unexported fields
}
ConsoleLogger implements Logger interface with colored console output.
func NewConsoleLogger ¶
func NewConsoleLogger(logLevel int) *ConsoleLogger
NewConsoleLogger creates a ConsoleLogger directly (for type-specific needs).
func (*ConsoleLogger) Codef ¶
func (l *ConsoleLogger) Codef(format string, v ...interface{})
Codef logs a code snippet message.
func (*ConsoleLogger) Complete ¶ added in v0.5.0
func (l *ConsoleLogger) Complete(stats ExecutionStats)
Complete logs the execution completion summary with statistics.
func (*ConsoleLogger) Debugf ¶
func (l *ConsoleLogger) Debugf(format string, v ...interface{})
Debugf logs a debug message.
func (*ConsoleLogger) Errorf ¶
func (l *ConsoleLogger) Errorf(format string, v ...interface{})
Errorf logs an error message.
func (*ConsoleLogger) Infof ¶
func (l *ConsoleLogger) Infof(format string, v ...interface{})
Infof logs an informational message.
func (*ConsoleLogger) LogStep ¶ added in v0.5.0
func (l *ConsoleLogger) LogStep(info StepInfo)
LogStep logs a step execution with status.
func (*ConsoleLogger) Mooncake ¶
func (l *ConsoleLogger) Mooncake()
Mooncake displays the mooncake banner.
func (*ConsoleLogger) SetLogLevel ¶
func (l *ConsoleLogger) SetLogLevel(logLevel int)
SetLogLevel sets the logging level for the logger.
func (*ConsoleLogger) SetLogLevelStr ¶
func (l *ConsoleLogger) SetLogLevelStr(logLevel string) error
SetLogLevelStr sets the logging level from a string value.
func (*ConsoleLogger) SetRedactor ¶ added in v0.5.0
func (l *ConsoleLogger) SetRedactor(redactor Redactor)
SetRedactor sets the redactor for automatic sensitive data redaction.
func (*ConsoleLogger) Textf ¶
func (l *ConsoleLogger) Textf(format string, v ...interface{})
Textf logs a plain text message.
func (*ConsoleLogger) WithPadLevel ¶
func (l *ConsoleLogger) WithPadLevel(padLevel int) Logger
WithPadLevel creates a new logger with the specified padding level.
type ConsoleSubscriber ¶ added in v0.5.0
type ConsoleSubscriber struct {
// contains filtered or unexported fields
}
ConsoleSubscriber implements event-based console logging
func NewConsoleSubscriber ¶ added in v0.5.0
func NewConsoleSubscriber(logLevel int, logFormat string) *ConsoleSubscriber
NewConsoleSubscriber creates a new console subscriber
func (*ConsoleSubscriber) Close ¶ added in v0.5.0
func (c *ConsoleSubscriber) Close()
Close implements the Subscriber interface
func (*ConsoleSubscriber) OnEvent ¶ added in v0.5.0
func (c *ConsoleSubscriber) OnEvent(event events.Event)
OnEvent handles incoming events
func (*ConsoleSubscriber) SetRedactor ¶ added in v0.5.0
func (c *ConsoleSubscriber) SetRedactor(r interface{ Redact(string) string })
SetRedactor sets the redactor for sensitive data
type ExecutionStats ¶ added in v0.5.0
ExecutionStats contains execution statistics.
type Logger ¶
type Logger interface {
Infof(format string, v ...interface{})
Debugf(format string, v ...interface{})
Errorf(format string, v ...interface{})
Codef(format string, v ...interface{})
Textf(format string, v ...interface{})
Mooncake()
SetLogLevel(logLevel int)
SetLogLevelStr(logLevel string) error
WithPadLevel(padLevel int) Logger
LogStep(info StepInfo)
Complete(stats ExecutionStats)
SetRedactor(redactor Redactor)
}
Logger interface defines the logging contract.
type ProgressInfo ¶
ProgressInfo tracks overall execution progress.
type QuietSubscriber ¶ added in v0.5.0
type QuietSubscriber struct {
// contains filtered or unexported fields
}
QuietSubscriber suppresses all output except failures and the final recap. Designed for CI pipelines and scripting where only failures matter.
func NewQuietSubscriber ¶ added in v0.5.0
func NewQuietSubscriber() *QuietSubscriber
NewQuietSubscriber creates a new QuietSubscriber.
func (*QuietSubscriber) Close ¶ added in v0.5.0
func (q *QuietSubscriber) Close()
Close implements the Subscriber interface.
func (*QuietSubscriber) OnEvent ¶ added in v0.5.0
func (q *QuietSubscriber) OnEvent(event events.Event)
OnEvent handles an incoming event.
type RunLogSubscriber ¶ added in v0.5.0
type RunLogSubscriber struct {
// contains filtered or unexported fields
}
RunLogSubscriber appends a compact run record to ~/.mooncake/runs.jsonl on EventRunCompleted. Write failures are silently dropped so they never fail a run.
func NewRunLogSubscriber ¶ added in v0.5.0
func NewRunLogSubscriber(configPath string) *RunLogSubscriber
NewRunLogSubscriber creates a subscriber that records runs under the given config basename.
func (*RunLogSubscriber) Close ¶ added in v0.5.0
func (r *RunLogSubscriber) Close()
Close implements the Subscriber interface.
func (*RunLogSubscriber) OnEvent ¶ added in v0.5.0
func (r *RunLogSubscriber) OnEvent(event events.Event)
OnEvent handles incoming events.
type StderrErrorSubscriber ¶ added in v0.5.0
type StderrErrorSubscriber struct {
// contains filtered or unexported fields
}
StderrErrorSubscriber writes a structured JSON error line to stderr on every step failure, regardless of the active output format.
func NewStderrErrorSubscriber ¶ added in v0.5.0
func NewStderrErrorSubscriber() *StderrErrorSubscriber
NewStderrErrorSubscriber creates a subscriber that writes to os.Stderr.
func (*StderrErrorSubscriber) Close ¶ added in v0.5.0
func (s *StderrErrorSubscriber) Close()
Close implements the Subscriber interface.
func (*StderrErrorSubscriber) OnEvent ¶ added in v0.5.0
func (s *StderrErrorSubscriber) OnEvent(event events.Event)
OnEvent handles incoming events.
type StepEntry ¶
type StepEntry struct {
Name string
Status string // "success", "error", "skipped", "running"
Level int // Nesting level for indentation
Timestamp time.Time
}
StepEntry represents a single step in the execution history.
type StepInfo ¶ added in v0.5.0
type StepInfo struct {
Name string
Level int // Nesting level for indentation
GlobalStep int // Cumulative step number
Status string // "running", "success", "error", "skipped"
}
StepInfo contains structured information about a step execution.
type TUIBuffer ¶
type TUIBuffer struct {
// contains filtered or unexported fields
}
TUIBuffer manages step history and message buffering.
func NewTUIBuffer ¶
NewTUIBuffer creates a new TUI buffer with specified history size.
func (*TUIBuffer) GetSnapshot ¶
func (b *TUIBuffer) GetSnapshot() BufferSnapshot
GetSnapshot returns an atomic snapshot of the buffer state.
func (*TUIBuffer) SetCompletion ¶ added in v0.5.0
func (b *TUIBuffer) SetCompletion(stats ExecutionStats)
SetCompletion sets execution completion statistics.
func (*TUIBuffer) SetCurrentStep ¶
func (b *TUIBuffer) SetCurrentStep(name string, progress ProgressInfo)
SetCurrentStep sets the currently executing step.
type TUIDisplay ¶
type TUIDisplay struct {
// contains filtered or unexported fields
}
TUIDisplay handles screen rendering for the animated TUI.
func NewTUIDisplay ¶
func NewTUIDisplay(animator *AnimationFrames, buffer *TUIBuffer, width, height int) *TUIDisplay
NewTUIDisplay creates a new TUI display renderer.
func (*TUIDisplay) Render ¶
func (d *TUIDisplay) Render() string
Render generates the complete screen output.
type TUILogger ¶
type TUILogger struct {
// contains filtered or unexported fields
}
TUILogger implements Logger interface with animated TUI display.
func NewTUILogger ¶
NewTUILogger creates a new TUI logger.
func (*TUILogger) Complete ¶ added in v0.5.0
func (l *TUILogger) Complete(stats ExecutionStats)
Complete logs the execution completion summary with statistics.
func (*TUILogger) Mooncake ¶
func (l *TUILogger) Mooncake()
Mooncake displays the mooncake banner (initializes display).
func (*TUILogger) SetLogLevel ¶
SetLogLevel sets the log level.
func (*TUILogger) SetLogLevelStr ¶
SetLogLevelStr sets the log level from a string.
func (*TUILogger) SetRedactor ¶ added in v0.5.0
SetRedactor sets the redactor for automatic sensitive data redaction.
func (*TUILogger) Start ¶
func (l *TUILogger) Start()
Start begins the animation and rendering loop.
func (*TUILogger) Stop ¶
func (l *TUILogger) Stop()
Stop stops the animation and shows final render.
func (*TUILogger) WithPadLevel ¶
WithPadLevel creates a new logger with the specified padding level.
type TUISubscriber ¶ added in v0.5.0
type TUISubscriber struct {
// contains filtered or unexported fields
}
TUISubscriber implements event-based TUI display.
func NewTUISubscriber ¶ added in v0.5.0
func NewTUISubscriber(logLevel int) (*TUISubscriber, error)
NewTUISubscriber creates a new TUI subscriber.
func (*TUISubscriber) Close ¶ added in v0.5.0
func (t *TUISubscriber) Close()
Close implements the Subscriber interface.
func (*TUISubscriber) OnEvent ¶ added in v0.5.0
func (t *TUISubscriber) OnEvent(event events.Event)
OnEvent handles incoming events.
func (*TUISubscriber) SetRedactor ¶ added in v0.5.0
func (t *TUISubscriber) SetRedactor(r Redactor)
SetRedactor sets the redactor for sensitive data.
func (*TUISubscriber) Start ¶ added in v0.5.0
func (t *TUISubscriber) Start()
Start begins the animation and rendering loop.
func (*TUISubscriber) Stop ¶ added in v0.5.0
func (t *TUISubscriber) Stop()
Stop stops the animation and shows final render.
type TerminalInfo ¶
TerminalInfo contains information about terminal capabilities.
func DetectTerminal ¶
func DetectTerminal() TerminalInfo
DetectTerminal detects terminal capabilities and returns terminal information.
type TestLogger ¶
type TestLogger struct {
Logs []LogEntry
// contains filtered or unexported fields
}
TestLogger implements Logger interface and captures log output for testing.
func NewTestLogger ¶
func NewTestLogger() *TestLogger
NewTestLogger creates a new TestLogger for use in tests.
func (*TestLogger) Codef ¶
func (t *TestLogger) Codef(format string, v ...interface{})
Codef logs a code snippet message.
func (*TestLogger) Complete ¶ added in v0.5.0
func (t *TestLogger) Complete(stats ExecutionStats)
Complete logs the execution completion summary with statistics.
func (*TestLogger) Contains ¶
func (t *TestLogger) Contains(substr string) bool
Contains checks if any log message contains the substring.
func (*TestLogger) ContainsLevel ¶
func (t *TestLogger) ContainsLevel(level, substr string) bool
ContainsLevel checks if any log at the specified level contains the substring.
func (*TestLogger) Count ¶
func (t *TestLogger) Count() int
Count returns the number of log entries.
func (*TestLogger) CountLevel ¶
func (t *TestLogger) CountLevel(level string) int
CountLevel returns the number of log entries at the specified level.
func (*TestLogger) Debugf ¶
func (t *TestLogger) Debugf(format string, v ...interface{})
Debugf logs a debug message.
func (*TestLogger) Errorf ¶
func (t *TestLogger) Errorf(format string, v ...interface{})
Errorf logs an error message.
func (*TestLogger) GetLogs ¶
func (t *TestLogger) GetLogs() []LogEntry
GetLogs returns a copy of all log entries.
func (*TestLogger) Infof ¶
func (t *TestLogger) Infof(format string, v ...interface{})
Infof logs an informational message.
func (*TestLogger) LogStep ¶ added in v0.5.0
func (t *TestLogger) LogStep(info StepInfo)
LogStep logs a step execution with status.
func (*TestLogger) Mooncake ¶
func (t *TestLogger) Mooncake()
Mooncake displays the mooncake banner.
func (*TestLogger) SetLogLevel ¶
func (t *TestLogger) SetLogLevel(logLevel int)
SetLogLevel sets the logging level for the logger.
func (*TestLogger) SetLogLevelStr ¶
func (t *TestLogger) SetLogLevelStr(logLevel string) error
SetLogLevelStr sets the logging level from a string value.
func (*TestLogger) SetRedactor ¶ added in v0.5.0
func (t *TestLogger) SetRedactor(redactor Redactor)
SetRedactor sets the redactor for automatic sensitive data redaction.
func (*TestLogger) Textf ¶
func (t *TestLogger) Textf(format string, v ...interface{})
Textf logs a plain text message.
func (*TestLogger) WithPadLevel ¶
func (t *TestLogger) WithPadLevel(padLevel int) Logger
WithPadLevel creates a new logger with the specified padding level.