logger

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CharmLogger

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

CharmLogger is a Logger implementation that wraps charmbracelet/log.Logger.

func NewCharmLogger

func NewCharmLogger(logger *log.Logger) *CharmLogger

NewCharmLogger creates a new CharmLogger with the given charmbracelet log.Logger. If logger is nil, it uses a default logger that writes to stderr.

func (*CharmLogger) Debug

func (l *CharmLogger) Debug(msg string, args ...any)

Debug logs a debug-level message with optional key-value pairs.

func (*CharmLogger) Error

func (l *CharmLogger) Error(msg string, args ...any)

Error logs an error-level message with optional key-value pairs.

func (*CharmLogger) Info

func (l *CharmLogger) Info(msg string, args ...any)

Info logs an info-level message with optional key-value pairs.

func (*CharmLogger) Warn

func (l *CharmLogger) Warn(msg string, args ...any)

Warn logs a warning-level message with optional key-value pairs.

func (*CharmLogger) With

func (l *CharmLogger) With(args ...any) Logger

With returns a new Logger with the given key-value pairs added to the context.

type Config

type Config struct {
	// Level sets the minimum log level. Messages below this level are discarded.
	Level Level
	// Format sets the output format (text or JSON).
	Format Format
	// Output sets where logs are written. If nil, defaults to os.Stderr.
	Output io.Writer
	// AddSource adds source code position (file and line number) to log records.
	AddSource bool
	// OmitTimestamp disables timestamp in logs if true
	OmitTimestamp bool
}

Config holds the configuration for creating a logger.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a Config with default settings:

Level:         LevelInfo
Format:        FormatText
Output:        os.Stdout
AddSource:     false
OmitTimestamp: false

type Format

type Format int

Format represents the log output format.

const (
	FormatText Format = iota
	FormatJSON
)

Available log output formats.

type Level

type Level int

Level represents the logging level.

const (
	LevelDebug Level = iota
	LevelInfo
	LevelWarn
	LevelError
)

Available logging levels

type Logger

type Logger interface {
	// Debug logs a debug-level message with optional key-value pairs.
	Debug(msg string, args ...any)

	// Info logs an info-level message with optional key-value pairs.
	Info(msg string, args ...any)

	// Warn logs a warning-level message with optional key-value pairs.
	Warn(msg string, args ...any)

	// Error logs an error-level message with optional key-value pairs.
	Error(msg string, args ...any)

	// With returns a new Logger with the given key-value pairs added to the context.
	With(args ...any) Logger
}

Logger defines the interface for logging operations.

func NewCharmFromConfig

func NewCharmFromConfig(cfg *Config) Logger

NewCharmFromConfig creates a new CharmLogger with given configuration. This function handles the conversion from generic Config to charmbracelet-specific types.

func NewMultiLogger

func NewMultiLogger(loggers ...Logger) Logger

NewMultiLogger creates a new MultiLogger that dispatches to all provided loggers. Each logger can have its own configuration (level, format, output). Log messages are sent to all loggers, and each logger applies its own filtering.

type MultiLogger

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

MultiLogger dispatches log calls to multiple underlying loggers.

func (*MultiLogger) Debug

func (m *MultiLogger) Debug(msg string, args ...any)

Debug logs a debug-level message to all underlying loggers.

func (*MultiLogger) Error

func (m *MultiLogger) Error(msg string, args ...any)

Error logs an error-level message to all underlying loggers.

func (*MultiLogger) GetLoggers

func (m *MultiLogger) GetLoggers() []Logger

GetLoggers returns a copy of the current loggers (for identification).

func (*MultiLogger) Info

func (m *MultiLogger) Info(msg string, args ...any)

Info logs an info-level message to all underlying loggers.

func (*MultiLogger) RemoveLoggerAt

func (m *MultiLogger) RemoveLoggerAt(index int)

RemoveLoggerAt removes the logger at the specified index.

func (*MultiLogger) Warn

func (m *MultiLogger) Warn(msg string, args ...any)

Warn logs a warning-level message to all underlying loggers.

func (*MultiLogger) With

func (m *MultiLogger) With(args ...any) Logger

With returns a new MultiLogger with the given key-value pairs added to the context of all underlying loggers.

Jump to

Keyboard shortcuts

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