Skip to content

logger

import "github.com/alehatsman/mooncake/internal/logger"

Package logger provides logging interfaces and implementations for mooncake.

Index

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 Fatalf

func Fatalf(logger Logger, format string, v ...interface{})

Fatalf logs an error and exits the program.

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

func ParseLogLevel(level string) (int, error)

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.

type AnimationFrames

AnimationFrames manages animation frames for the mooncake character.

type AnimationFrames struct {
    // contains filtered or unexported fields
}

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

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.

type ConsoleLogger struct {
    // contains filtered or unexported fields
}

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

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

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

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

ConsoleSubscriber implements event-based console logging

type ConsoleSubscriber struct {
    // contains filtered or unexported fields
}

func NewConsoleSubscriber

func NewConsoleSubscriber(logLevel int, logFormat string) *ConsoleSubscriber

NewConsoleSubscriber creates a new console subscriber

func (*ConsoleSubscriber) Close

func (c *ConsoleSubscriber) Close()

Close implements the Subscriber interface

func (*ConsoleSubscriber) OnEvent

func (c *ConsoleSubscriber) OnEvent(event events.Event)

OnEvent handles incoming events

func (*ConsoleSubscriber) SetRedactor

func (c *ConsoleSubscriber) SetRedactor(r interface{ Redact(string) string })

SetRedactor sets the redactor for sensitive data

type ExecutionStats

ExecutionStats contains execution statistics.

type ExecutionStats struct {
    Duration time.Duration
    Executed int
    Skipped  int
    Failed   int
}

type LogEntry

LogEntry represents a single log entry.

type LogEntry struct {
    Level   string
    Message string
}

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

func NewLogger(logLevel int) Logger

NewLogger creates a new ConsoleLogger with the specified log level.

type ProgressInfo

ProgressInfo tracks overall execution progress.

type ProgressInfo struct {
    Current int
    Total   int
}

type Redactor

Redactor interface for redacting sensitive data in logs.

type Redactor interface {
    Redact(string) string
}

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.

type TUIBuffer struct {
    // contains filtered or unexported fields
}

func NewTUIBuffer

func NewTUIBuffer(historySize int) *TUIBuffer

NewTUIBuffer creates a new TUI buffer with specified history size.

func (*TUIBuffer) AddDebug

func (b *TUIBuffer) AddDebug(message string)

AddDebug adds a debug message to the buffer.

func (*TUIBuffer) AddError

func (b *TUIBuffer) AddError(message string)

AddError adds an error message to the buffer.

func (*TUIBuffer) AddStep

func (b *TUIBuffer) AddStep(entry StepEntry)

AddStep adds a step to the history (circular buffer).

func (*TUIBuffer) GetSnapshot

func (b *TUIBuffer) GetSnapshot() BufferSnapshot

GetSnapshot returns an atomic snapshot of the buffer state.

func (*TUIBuffer) SetCompletion

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

TUIDisplay handles screen rendering for the animated TUI.

type TUIDisplay struct {
    // contains filtered or unexported fields
}

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

TUILogger implements Logger interface with animated TUI display.

type TUILogger struct {
    // contains filtered or unexported fields
}

func NewTUILogger

func NewTUILogger(logLevel int) (*TUILogger, error)

NewTUILogger creates a new TUI logger.

func (*TUILogger) Codef

func (l *TUILogger) Codef(format string, v ...interface{})

Codef logs formatted code.

func (*TUILogger) Complete

func (l *TUILogger) Complete(stats ExecutionStats)

Complete logs the execution completion summary with statistics.

func (*TUILogger) Debugf

func (l *TUILogger) Debugf(format string, v ...interface{})

Debugf logs a debug message.

func (*TUILogger) Errorf

func (l *TUILogger) Errorf(format string, v ...interface{})

Errorf logs an error message.

func (*TUILogger) Infof

func (l *TUILogger) Infof(_ string, _ ...interface{})

Infof logs an info message (ignored in TUI mode - use LogStep for steps).

func (*TUILogger) LogStep

func (l *TUILogger) LogStep(info StepInfo)

LogStep handles structured step logging.

func (*TUILogger) Mooncake

func (l *TUILogger) Mooncake()

Mooncake displays the mooncake banner (initializes display).

func (*TUILogger) SetLogLevel

func (l *TUILogger) SetLogLevel(logLevel int)

SetLogLevel sets the log level.

func (*TUILogger) SetLogLevelStr

func (l *TUILogger) SetLogLevelStr(logLevel string) error

SetLogLevelStr sets the log level from a string.

func (*TUILogger) SetRedactor

func (l *TUILogger) SetRedactor(redactor Redactor)

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) Textf

func (l *TUILogger) Textf(format string, v ...interface{})

Textf logs plain text.

func (*TUILogger) WithPadLevel

func (l *TUILogger) WithPadLevel(padLevel int) Logger

WithPadLevel creates a new logger with the specified padding level.

type TUISubscriber

TUISubscriber implements event-based TUI display.

type TUISubscriber struct {
    // contains filtered or unexported fields
}

func NewTUISubscriber

func NewTUISubscriber(logLevel int) (*TUISubscriber, error)

NewTUISubscriber creates a new TUI subscriber.

func (*TUISubscriber) Close

func (t *TUISubscriber) Close()

Close implements the Subscriber interface.

func (*TUISubscriber) OnEvent

func (t *TUISubscriber) OnEvent(event events.Event)

OnEvent handles incoming events.

func (*TUISubscriber) SetRedactor

func (t *TUISubscriber) SetRedactor(r Redactor)

SetRedactor sets the redactor for sensitive data.

func (*TUISubscriber) Start

func (t *TUISubscriber) Start()

Start begins the animation and rendering loop.

func (*TUISubscriber) Stop

func (t *TUISubscriber) Stop()

Stop stops the animation and shows final render.

type TerminalInfo

TerminalInfo contains information about terminal capabilities.

type TerminalInfo struct {
    IsTerminal   bool
    SupportsANSI bool
    Width        int
    Height       int
}

func DetectTerminal

func DetectTerminal() TerminalInfo

DetectTerminal detects terminal capabilities and returns terminal information.

type TestLogger

TestLogger implements Logger interface and captures log output for testing.

type TestLogger struct {
    Logs []LogEntry
    // contains filtered or unexported fields
}

func NewTestLogger

func NewTestLogger() *TestLogger

NewTestLogger creates a new TestLogger for use in tests.

func (*TestLogger) Clear

func (t *TestLogger) Clear()

Clear removes all log entries.

func (*TestLogger) Codef

func (t *TestLogger) Codef(format string, v ...interface{})

Codef logs a code snippet message.

func (*TestLogger) Complete

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

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

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.

Generated by gomarkdoc