logger¶
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
- func NewAgentSubscriber() *AgentSubscriber
- func (a *AgentSubscriber) Close()
- func (a *AgentSubscriber) OnEvent(event events.Event)
- type AnimationFrames
- func LoadEmbeddedFrames() (*AnimationFrames, error)
- func LoadFramesFromFile(path string) (*AnimationFrames, error)
- func LoadFramesFromString(content string) (*AnimationFrames, error)
- func (a *AnimationFrames) Current() []string
- func (a *AnimationFrames) FrameCount() int
- func (a *AnimationFrames) Next() []string
- type BufferSnapshot
- type ConsoleLogger
- func NewConsoleLogger(logLevel int) *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
- func NewConsoleSubscriber(logLevel int, logFormat string, streamOutput bool) *ConsoleSubscriber
- func (c *ConsoleSubscriber) Close()
- func (c *ConsoleSubscriber) OnEvent(event events.Event)
- func (c *ConsoleSubscriber) SetRedactor(r interface{ Redact(string) string })
- type DiscardLogger
- func NewDiscardLogger() *DiscardLogger
- func (DiscardLogger) Codef(string, ...interface{})
- func (DiscardLogger) Complete(ExecutionStats)
- func (DiscardLogger) Debugf(string, ...interface{})
- func (DiscardLogger) Errorf(string, ...interface{})
- func (DiscardLogger) Infof(string, ...interface{})
- func (DiscardLogger) LogStep(StepInfo)
- func (DiscardLogger) Mooncake()
- func (DiscardLogger) SetLogLevel(int)
- func (DiscardLogger) SetLogLevelStr(string) error
- func (DiscardLogger) SetRedactor(Redactor)
- func (DiscardLogger) Textf(string, ...interface{})
- func (d DiscardLogger) WithPadLevel(int) Logger
- type ExecutionStats
- type FirstRunHintSubscriber
- func NewFirstRunHintSubscriber(out io.Writer, outputFormat string) *FirstRunHintSubscriber
- func (s *FirstRunHintSubscriber) Close()
- func (s *FirstRunHintSubscriber) OnEvent(event events.Event)
- type LogEntry
- type Logger
- func NewLogger(logLevel int) Logger
- type ProgressInfo
- type QuietSubscriber
- func NewQuietSubscriber() *QuietSubscriber
- func (q *QuietSubscriber) Close()
- func (q *QuietSubscriber) OnEvent(event events.Event)
- type Redactor
- type RunLogSubscriber
- func NewRunLogSubscriber(configPath string) *RunLogSubscriber
- func (r *RunLogSubscriber) Close()
- func (r *RunLogSubscriber) OnEvent(event events.Event)
- type StderrErrorSubscriber
- func NewStderrErrorSubscriber() *StderrErrorSubscriber
- func (s *StderrErrorSubscriber) Close()
- func (s *StderrErrorSubscriber) OnEvent(event events.Event)
- type StepEntry
- type StepInfo
- type TUIBuffer
- func NewTUIBuffer(historySize int) *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
- func NewTUIDisplay(animator AnimationFrames, buffer TUIBuffer, width, height int) *TUIDisplay
- func (d *TUIDisplay) Render() string
- type TUILogger
- func NewTUILogger(logLevel int) (*TUILogger, error)
- 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
- func NewTUISubscriber(logLevel int) (*TUISubscriber, error)
- func (t *TUISubscriber) Close()
- func (t *TUISubscriber) OnEvent(event events.Event)
- func (t *TUISubscriber) SetRedactor(r Redactor)
- func (t *TUISubscriber) Start()
- func (t *TUISubscriber) Stop()
- type TerminalInfo
- func DetectTerminal() TerminalInfo
- type TestLogger
- func NewTestLogger() *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
)
Step status constants used across all logger implementations
const (
StatusRunning = "running"
StatusSuccess = "success"
StatusError = "error"
StatusSkipped = "skipped"
)
func GetTerminalSize¶
GetTerminalSize returns the current terminal size. Returns default 80x24 if detection fails.
func IsTUISupported¶
IsTUISupported checks if the terminal supports TUI mode. Returns true if terminal is detected, supports ANSI codes, and meets minimum size requirements.
func ParseLogLevel¶
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¶
StripANSI removes all ANSI escape codes from a string. This includes color codes, cursor movement, and other terminal control sequences.
Example:
func TruncateANSI¶
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:
func VisibleLength¶
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:
type AgentSubscriber¶
AgentSubscriber writes one flat JSON line per lifecycle event to stdout. No ANSI, no human framing — designed for programmatic consumption.
func NewAgentSubscriber¶
NewAgentSubscriber creates a new AgentSubscriber.
func (*AgentSubscriber) Close¶
Close implements the Subscriber interface.
func (*AgentSubscriber) OnEvent¶
OnEvent handles an incoming event and writes a JSONL record.
type AnimationFrames¶
AnimationFrames manages animation frames for the mooncake character.
func LoadEmbeddedFrames¶
LoadEmbeddedFrames loads animation frames from the embedded content.
func LoadFramesFromFile¶
LoadFramesFromFile loads animation frames from a file. Frames are expected to be 3 lines each, separated by blank lines.
func LoadFramesFromString¶
LoadFramesFromString loads animation frames from a string. Frames are expected to be 3 lines each, separated by blank lines.
func (*AnimationFrames) Current¶
Current returns the current frame without advancing
func (*AnimationFrames) FrameCount¶
FrameCount returns the total number of frames
func (*AnimationFrames) Next¶
Next advances to the next frame and returns it
type BufferSnapshot¶
BufferSnapshot is an atomic snapshot of the buffer state for rendering.
type BufferSnapshot struct {
StepHistory []StepEntry
CurrentStep string
Progress ProgressInfo
DebugMessages []string
ErrorMessages []string
Completion *ExecutionStats
}
type ConsoleLogger¶
ConsoleLogger implements Logger interface with colored console output.
func NewConsoleLogger¶
NewConsoleLogger creates a ConsoleLogger directly (for type-specific needs).
func (*ConsoleLogger) Codef¶
Codef logs a code snippet message.
func (*ConsoleLogger) Complete¶
Complete logs the execution completion summary with statistics.
func (*ConsoleLogger) Debugf¶
Debugf logs a debug message.
func (*ConsoleLogger) Errorf¶
Errorf logs an error message.
func (*ConsoleLogger) Infof¶
Infof logs an informational message.
func (*ConsoleLogger) LogStep¶
LogStep logs a step execution with status.
func (*ConsoleLogger) Mooncake¶
Mooncake displays the mooncake banner.
func (*ConsoleLogger) SetLogLevel¶
SetLogLevel sets the logging level for the logger.
func (*ConsoleLogger) SetLogLevelStr¶
SetLogLevelStr sets the logging level from a string value.
func (*ConsoleLogger) SetRedactor¶
SetRedactor sets the redactor for automatic sensitive data redaction.
func (*ConsoleLogger) Textf¶
Textf logs a plain text message.
func (*ConsoleLogger) WithPadLevel¶
WithPadLevel creates a new logger with the specified padding level.
type ConsoleSubscriber¶
ConsoleSubscriber implements event-based console logging
func NewConsoleSubscriber¶
NewConsoleSubscriber creates a new console subscriber. streamOutput=false matches the historical `mooncake apply` UX (step-start/end markers only at info; shell stdout/stderr only at debug). `mooncake task` constructs with streamOutput=true.
func (*ConsoleSubscriber) Close¶
Close implements the Subscriber interface
func (*ConsoleSubscriber) OnEvent¶
OnEvent handles incoming events
func (*ConsoleSubscriber) SetRedactor¶
SetRedactor sets the redactor for sensitive data
type DiscardLogger¶
DiscardLogger implements Logger by ignoring every call.
Use it on a production code path that needs to satisfy the Logger interface but has no place to surface the output. The MCP server's best-effort plan-inspection calls (internal/mcp/tools.go) are the motivating case: InspectPlan logs are noise to the LLM client and dropping them avoids reaching for NewTestLogger (which retains every entry in a Logs slice — see F022).
func NewDiscardLogger¶
NewDiscardLogger returns a Logger that drops every entry.
func (DiscardLogger) Codef¶
func (DiscardLogger) Complete¶
func (DiscardLogger) Debugf¶
func (DiscardLogger) Errorf¶
func (DiscardLogger) Infof¶
func (DiscardLogger) LogStep¶
func (DiscardLogger) Mooncake¶
func (DiscardLogger) SetLogLevel¶
func (DiscardLogger) SetLogLevelStr¶
func (DiscardLogger) SetRedactor¶
func (DiscardLogger) Textf¶
func (DiscardLogger) WithPadLevel¶
type ExecutionStats¶
ExecutionStats contains execution statistics.
type FirstRunHintSubscriber¶
FirstRunHintSubscriber prints a single line of next-step guidance after the first successful `mooncake apply` on a host. It is a one-shot: once the marker file \~/.mooncake/.first-run-completed exists, the subscriber is a no-op. Spec 40 §"First-run hint".
Suppression rules: - Marker file already exists. - The run failed (we don't celebrate failures). - Output format is anything other than text (`agent`, `json`, `quiet`) so the hint cannot corrupt downstream parsers. - MOONCAKE_NO_HINTS=1 in the environment.
func NewFirstRunHintSubscriber¶
NewFirstRunHintSubscriber returns a subscriber that prints the hint to out (typically os.Stdout) on the first successful run. outputFormat is the CLI's --output-format value; the hint is only printed when it is empty or "text".
func (*FirstRunHintSubscriber) Close¶
Close implements the Subscriber interface.
func (*FirstRunHintSubscriber) OnEvent¶
OnEvent prints the hint when the run completes successfully and no marker exists. Marker creation and printing are best-effort: a failure to write the marker just means the hint may print again next run.
type LogEntry¶
LogEntry represents a single log entry.
type Logger¶
Logger interface defines the logging contract.
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)
}
func NewLogger¶
NewLogger creates a new ConsoleLogger with the specified log level.
type ProgressInfo¶
ProgressInfo tracks overall execution progress.
type QuietSubscriber¶
QuietSubscriber suppresses all output except failures and the final recap. Designed for CI pipelines and scripting where only failures matter.
func NewQuietSubscriber¶
NewQuietSubscriber creates a new QuietSubscriber.
func (*QuietSubscriber) Close¶
Close implements the Subscriber interface.
func (*QuietSubscriber) OnEvent¶
OnEvent handles an incoming event.
type Redactor¶
Redactor interface for redacting sensitive data in logs.
type RunLogSubscriber¶
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¶
NewRunLogSubscriber creates a subscriber that records runs under the given config basename.
func (*RunLogSubscriber) Close¶
Close implements the Subscriber interface.
func (*RunLogSubscriber) OnEvent¶
OnEvent handles incoming events.
type StderrErrorSubscriber¶
StderrErrorSubscriber writes a structured JSON error line to stderr on every step failure, regardless of the active output format.
func NewStderrErrorSubscriber¶
NewStderrErrorSubscriber creates a subscriber that writes to os.Stderr.
func (*StderrErrorSubscriber) Close¶
Close implements the Subscriber interface.
func (*StderrErrorSubscriber) OnEvent¶
OnEvent handles incoming events.
type StepEntry¶
StepEntry represents a single step in the execution history.
type StepEntry struct {
Name string
Status string // "success", "error", "skipped", "running"
Level int // Nesting level for indentation
Timestamp time.Time
}
type StepInfo¶
StepInfo contains structured information about a step execution.
type StepInfo struct {
Name string
Level int // Nesting level for indentation
GlobalStep int // Cumulative step number
Status string // "running", "success", "error", "skipped"
}
type TUIBuffer¶
TUIBuffer manages step history and message buffering.
func NewTUIBuffer¶
NewTUIBuffer creates a new TUI buffer with specified history size.
func (*TUIBuffer) AddDebug¶
AddDebug adds a debug message to the buffer.
func (*TUIBuffer) AddError¶
AddError adds an error message to the buffer.
func (*TUIBuffer) AddStep¶
AddStep adds a step to the history (circular buffer).
func (*TUIBuffer) GetSnapshot¶
GetSnapshot returns an atomic snapshot of the buffer state.
func (*TUIBuffer) SetCompletion¶
SetCompletion sets execution completion statistics.
func (*TUIBuffer) SetCurrentStep¶
SetCurrentStep sets the currently executing step.
type TUIDisplay¶
TUIDisplay handles screen rendering for the animated TUI.
func NewTUIDisplay¶
NewTUIDisplay creates a new TUI display renderer.
func (*TUIDisplay) Render¶
Render generates the complete screen output.
type TUILogger¶
TUILogger implements Logger interface with animated TUI display.
func NewTUILogger¶
NewTUILogger creates a new TUI logger.
func (*TUILogger) Codef¶
Codef logs formatted code.
func (*TUILogger) Complete¶
Complete logs the execution completion summary with statistics.
func (*TUILogger) Debugf¶
Debugf logs a debug message.
func (*TUILogger) Errorf¶
Errorf logs an error message.
func (*TUILogger) Infof¶
Infof logs an info message (ignored in TUI mode - use LogStep for steps).
func (*TUILogger) LogStep¶
LogStep handles structured step logging.
func (*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¶
SetRedactor sets the redactor for automatic sensitive data redaction.
func (*TUILogger) Start¶
Start begins the animation and rendering loop.
func (*TUILogger) Stop¶
Stop stops the animation and shows final render.
func (*TUILogger) Textf¶
Textf logs plain text.
func (*TUILogger) WithPadLevel¶
WithPadLevel creates a new logger with the specified padding level.
type TUISubscriber¶
TUISubscriber implements event-based TUI display.
func NewTUISubscriber¶
NewTUISubscriber creates a new TUI subscriber.
func (*TUISubscriber) Close¶
Close implements the Subscriber interface.
func (*TUISubscriber) OnEvent¶
OnEvent handles incoming events.
func (*TUISubscriber) SetRedactor¶
SetRedactor sets the redactor for sensitive data.
func (*TUISubscriber) Start¶
Start begins the animation and rendering loop.
func (*TUISubscriber) Stop¶
Stop stops the animation and shows final render.
type TerminalInfo¶
TerminalInfo contains information about terminal capabilities.
func DetectTerminal¶
DetectTerminal detects terminal capabilities and returns terminal information.
type TestLogger¶
TestLogger implements Logger interface and captures log output for testing.
func NewTestLogger¶
NewTestLogger creates a new TestLogger for use in tests.
func (*TestLogger) Clear¶
Clear removes all log entries.
func (*TestLogger) Codef¶
Codef logs a code snippet message.
func (*TestLogger) Complete¶
Complete logs the execution completion summary with statistics.
func (*TestLogger) Contains¶
Contains checks if any log message contains the substring.
func (*TestLogger) ContainsLevel¶
ContainsLevel checks if any log at the specified level contains the substring.
func (*TestLogger) Count¶
Count returns the number of log entries.
func (*TestLogger) CountLevel¶
CountLevel returns the number of log entries at the specified level.
func (*TestLogger) Debugf¶
Debugf logs a debug message.
func (*TestLogger) Errorf¶
Errorf logs an error message.
func (*TestLogger) GetLogs¶
GetLogs returns a copy of all log entries.
func (*TestLogger) Infof¶
Infof logs an informational message.
func (*TestLogger) LogStep¶
LogStep logs a step execution with status.
func (*TestLogger) Mooncake¶
Mooncake displays the mooncake banner.
func (*TestLogger) SetLogLevel¶
SetLogLevel sets the logging level for the logger.
func (*TestLogger) SetLogLevelStr¶
SetLogLevelStr sets the logging level from a string value.
func (*TestLogger) SetRedactor¶
SetRedactor sets the redactor for automatic sensitive data redaction.
func (*TestLogger) Textf¶
Textf logs a plain text message.
func (*TestLogger) WithPadLevel¶
WithPadLevel creates a new logger with the specified padding level.
Generated by gomarkdoc