logging

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package logging provides configurable logging utilities for squad.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(message string, args ...interface{})

func DebugContext

func DebugContext(ctx context.Context, message string, args ...interface{})

func DetermineLogLevel

func DetermineLogLevel(levelStr string) slog.Level

DetermineLogLevel maps a string level to its slog equivalent.

func Error

func Error(firstArg interface{}, args ...interface{})

func ErrorContext

func ErrorContext(ctx context.Context, firstArg interface{}, args ...interface{})

func Info

func Info(message string, args ...interface{})

func InfoContext

func InfoContext(ctx context.Context, message string, args ...interface{})

func Initialize

func Initialize(logLevelStr, outputFormat string, quiet, verbose bool) error

Initialize sets up the global logger.

func IsQuiet

func IsQuiet() bool

IsQuiet reports whether the global logger suppresses non-error output.

func Output

func Output(data interface{})

Output writes data using the global logger's output format.

func OutputContext

func OutputContext(ctx context.Context, data interface{})

func SetQuiet

func SetQuiet(quiet bool)

func SetVerbose

func SetVerbose(verbose bool)

func Warn

func Warn(message string, args ...interface{})

func WarnContext

func WarnContext(ctx context.Context, message string, args ...interface{})

func WithLogger

func WithLogger(ctx context.Context, l *CustomLogger) context.Context

WithLogger returns a context that carries the provided logger.

Types

type CustomLogger

type CustomLogger struct {
	LogLevel      slog.Level
	OutputType    OutputType
	Quiet         bool
	ConsoleWriter io.Writer
	OutputWriter  io.Writer
	Verbose       bool
	Prefix        string // Optional prefix prepended to all log messages (e.g., "[bg-1] ")
}

CustomLogger wraps logging functionality with formatting options.

func FromContext

func FromContext(ctx context.Context) *CustomLogger

FromContext returns the logger stored in ctx or the global logger.

func NewCustomLogger

func NewCustomLogger(level slog.Level) *CustomLogger

NewCustomLogger creates a logger with the provided minimum slog level.

func (*CustomLogger) Debug

func (l *CustomLogger) Debug(format string, args ...interface{})

func (*CustomLogger) Error

func (l *CustomLogger) Error(firstArg interface{}, args ...interface{})

func (*CustomLogger) Info

func (l *CustomLogger) Info(format string, args ...interface{})

func (*CustomLogger) Output

func (l *CustomLogger) Output(data interface{})

Output writes data using the logger's configured output format.

func (*CustomLogger) SetQuiet

func (l *CustomLogger) SetQuiet(quiet bool)

func (*CustomLogger) SetVerbose

func (l *CustomLogger) SetVerbose(verbose bool)

func (*CustomLogger) Warn

func (l *CustomLogger) Warn(format string, args ...interface{})

func (*CustomLogger) WithPrefix

func (l *CustomLogger) WithPrefix(prefix string) *CustomLogger

WithPrefix returns a shallow copy of the logger with the given prefix. The prefix is prepended to every log line, making it easy to distinguish output from different child agents or background tasks.

type LogLevel

type LogLevel int

LogLevel represents the supported log severity levels.

const (
	// InfoLevel emits informational log entries.
	InfoLevel LogLevel = iota
	// WarnLevel emits warning log entries.
	WarnLevel
	// DebugLevel emits verbose debug log entries.
	DebugLevel
	// ErrorLevel emits error log entries.
	ErrorLevel
)

type OutputType

type OutputType int

OutputType defines the available logger output formats.

const (
	// PlainOutput emits uncolored text output.
	PlainOutput OutputType = iota
	// ColorOutput emits ANSI-colored text output.
	ColorOutput
	// JSONOutput emits structured JSON output.
	JSONOutput
)

Jump to

Keyboard shortcuts

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