log

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package log provides a leveled logger with emoji-rich console output for the iterion workflow engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BlockPreview

func BlockPreview(s string, max int) string

BlockPreview returns s truncated to max bytes, preserving newlines. If truncated, a "...[truncated]" marker is appended on a new line.

func Truncate

func Truncate(s string, max int) string

Truncate returns s truncated to max bytes with a suffix if it exceeds max. Useful for limiting field sizes in log output and events.

func TruncateMiddle

func TruncateMiddle(s string, max int) string

TruncateMiddle returns s shortened to at most max runes by replacing the middle with an ellipsis (…), keeping the beginning and the end. If s already fits in max runes it is returned unchanged. If max <= 0 an empty string is returned. The ellipsis itself counts as one rune toward the limit; when the remaining budget is odd the head receives the extra rune.

Unlike Truncate, which counts bytes, TruncateMiddle counts runes and always slices on rune boundaries — safe for arbitrary UTF-8 input such as IDs, hashes, paths, or URLs.

Types

type Level

type Level int

Level represents a logging verbosity level.

const (
	LevelError Level = iota
	LevelWarn
	LevelInfo
	LevelDebug
	LevelTrace
)

func ParseLevel

func ParseLevel(s string) (Level, error)

ParseLevel converts a string to a Level. Case-insensitive. Returns LevelInfo if the string is empty.

func ResolveLevel

func ResolveLevel(explicit string, envVar string) (Level, error)

ResolveLevel resolves the log level from explicit value, env var fallback, and default. The explicit value takes precedence over the env var.

func (Level) String

func (l Level) String() string

String returns the human-readable name of the level.

type Logger

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

Logger is a leveled logger that writes emoji-rich formatted output.

func New

func New(level Level, w io.Writer) *Logger

New creates a new Logger with the given level and writer.

func Nop

func Nop() *Logger

Nop returns a logger that discards all output (level below error).

func (*Logger) Debug

func (l *Logger) Debug(format string, args ...any)

Debug logs at debug level with 🔍 prefix.

func (*Logger) Error

func (l *Logger) Error(format string, args ...any)

Error logs at error level with ❌ prefix.

func (*Logger) Info

func (l *Logger) Info(format string, args ...any)

Info logs at info level with a contextual prefix (caller chooses emoji).

func (*Logger) IsEnabled

func (l *Logger) IsEnabled(level Level) bool

IsEnabled returns true if the given level would produce output.

func (*Logger) Level

func (l *Logger) Level() Level

Level returns the configured log level.

func (*Logger) LogBlock

func (l *Logger) LogBlock(level Level, emoji string, header string, body string)

LogBlock logs a header line followed by a multi-line indented body block. The entire output is written in a single mutex-protected write to prevent interleaving from concurrent goroutines. If body is empty, only the header is printed.

func (*Logger) Logf

func (l *Logger) Logf(level Level, emoji string, format string, args ...any)

Logf logs a pre-formatted message at the given level with a custom emoji prefix. This is useful when callers want to choose their own emoji.

func (*Logger) Trace

func (l *Logger) Trace(format string, args ...any)

Trace logs at trace level with 🔬 prefix.

func (*Logger) Warn

func (l *Logger) Warn(format string, args ...any)

Warn logs at warn level with ⚠️ prefix.

func (*Logger) Writer

func (l *Logger) Writer() io.Writer

Writer returns the underlying io.Writer. Useful for callers that need to compose new loggers that tee output to additional sinks (e.g. a per-run buffer) without losing the original destination.

Jump to

Keyboard shortcuts

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