logging

package
v0.0.217 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

  • **Workflow**: Workflow execution and management
  • **Agent**: MCP agent and client operations
  • **TUI**: Terminal user interface operations
  • **API**: API layer operations and handler management

Integration with slog

The logging system integrates with Go's standard slog package:

  • Uses slog.Handler implementations for output formatting
  • Converts custom LogLevel to slog.Level for compatibility
  • Supports slog.Attr for structured logging attributes
  • Provides fallback to global slog logger when needed

Error Handling and Reliability

The logging system handles various failure scenarios:

## Channel Overflow (TUI Mode)

  • Non-blocking channel sends with fallback to stderr
  • Buffer size configuration to prevent overflow
  • Critical error messages when log delivery fails

## Initialization Failures

  • Graceful fallback to stderr for uninitialized logger
  • Clear error messages when logging system is not ready
  • Safe operation even with nil handlers or channels

## Mode Switching

  • Clean shutdown of TUI channel with CloseTUIChannel()
  • Prevention of further use after channel closure
  • Safe concurrent access to logging state

Performance Characteristics

## CLI Mode

  • Direct write to output with minimal overhead
  • Level filtering at handler level for efficiency
  • No memory allocation for filtered-out messages

## TUI Mode

  • Buffered channel prevents UI blocking
  • Configurable buffer size (default 2048 entries)
  • Non-blocking sends with overflow handling
  • Memory-efficient message passing

Thread Safety

The logging system is fully thread-safe:

  • Safe concurrent logging from multiple goroutines
  • Protected access to shared logging state
  • Channel operations designed for concurrent use
  • No data races in mode switching or configuration

Cleanup and Shutdown

Proper cleanup is essential for TUI mode:

// Clean shutdown in TUI mode
defer logging.CloseTUIChannel()

This ensures:

  • TUI log channel is properly closed
  • No goroutine leaks from channel readers
  • Clean application termination

The logging package provides a robust foundation for muster's diagnostic and monitoring capabilities across both interactive and non-interactive execution modes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Audit

func Audit(event AuditEvent)

Audit logs a structured audit event for security-sensitive operations. Audit events are always logged at INFO level and include a special [AUDIT] prefix to make them easily filterable by log aggregation systems.

Example output: [AUDIT] action=token_exchange outcome=success session=abc12345... user=xyz789... target=mcp-kubernetes

func Debug

func Debug(subsystem string, messageFmt string, args ...interface{})

Debug logs a debug message.

func Error

func Error(subsystem string, err error, messageFmt string, args ...interface{})

Error logs an error message.

func Info

func Info(subsystem string, messageFmt string, args ...interface{})

Info logs an informational message.

func InitForCLI

func InitForCLI(filterLevel LogLevel, output io.Writer)

InitForCLI initializes the logging system for CLI mode.

func Initcommon

func Initcommon(mode string, level LogLevel, output io.Writer, channelBufferSize int) <-chan LogEntry

Initcommon initializes the logger for either TUI or CLI mode. This should be called once at application startup.

func TruncateSessionID

func TruncateSessionID(sessionID string) string

TruncateSessionID returns a truncated session ID for secure logging. This prevents full session IDs from appearing in logs while still providing enough context for debugging correlation. Format: first 8 chars + "..." (e.g., "abc12345...")

func Warn

func Warn(subsystem string, messageFmt string, args ...interface{})

Warn logs a warning message.

Types

type AuditEvent

type AuditEvent struct {
	// Action is the type of action being audited (e.g., "token_exchange", "auth_login")
	Action string
	// Outcome indicates whether the action succeeded or failed
	Outcome string // "success" or "failure"
	// SessionID is the truncated session identifier
	SessionID string
	// UserID is the truncated user identifier (from JWT sub claim)
	UserID string
	// Target is the target of the action (e.g., server name, endpoint)
	Target string
	// Details provides additional context-specific information
	Details string
	// Error contains the error message if Outcome is "failure"
	Error string
}

AuditEvent represents a structured audit log event for security-sensitive operations. These events can be collected by external audit systems for compliance monitoring.

type LogEntry

type LogEntry struct {
	Timestamp  time.Time
	Level      LogLevel
	Subsystem  string
	Message    string
	Err        error
	Attributes []slog.Attr // Using slog.Attr for flexibility
}

LogEntry is the structured log entry passed to the TUI.

type LogLevel

type LogLevel int

LogLevel defines the severity of the log entry.

const (
	LevelDebug LogLevel = iota
	LevelInfo
	LevelWarn
	LevelError
)

func (LogLevel) SlogLevel

func (l LogLevel) SlogLevel() slog.Level

func (LogLevel) String

func (l LogLevel) String() string

String makes LogLevel satisfy the fmt.Stringer interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL