Documentation
¶
Overview ¶
Package clog provides structured CLI logging with terminal-aware colours, hyperlinks, and spinners.
It uses a zerolog-style fluent API for building log entries:
clog.Info().Str("port", "8080").Msg("Server started")
The default output is a pretty terminal formatter. A custom Handler can be set for alternative formats (e.g. JSON).
Index ¶
- Constants
- Variables
- func ColorsDisabled() bool
- func Configure(cfg *Config)
- func ConfigureColorOutput(mode string)
- func ConfigureVerbose(verbose bool)
- func DefaultMessageStyles() map[Level]*lipgloss.Style
- func DefaultValueStyles() map[string]*lipgloss.Style
- func Hyperlink(url, text string) string
- func IsTerminal() bool
- func IsVerbose() bool
- func PathLink(path string, lineNumber int) string
- func SetColorMode(mode ColorMode)
- func SetExitFunc(fn func(int))
- func SetFieldStyleLevel(level Level)
- func SetFieldTimeFormat(format string)
- func SetHandler(h Handler)
- func SetHyperlinkColumnFormat(format string)
- func SetHyperlinkDirFormat(format string)
- func SetHyperlinkFileFormat(format string)
- func SetHyperlinkLineFormat(format string)
- func SetHyperlinkPathFormat(format string)
- func SetHyperlinksEnabled(enabled bool)
- func SetLevel(level Level)
- func SetLevelAlign(align LevelAlign)
- func SetLevelFromEnv(envVar string)
- func SetLevelLabels(labels LevelMap)
- func SetOmitEmpty(omit bool)
- func SetOmitQuotes(omit bool)
- func SetOmitZero(omit bool)
- func SetOutput(out io.Writer)
- func SetParts(order ...Part)
- func SetPrefixes(prefixes LevelMap)
- func SetQuoteChar(char rune)
- func SetQuoteChars(openChar, closeChar rune)
- func SetQuoteMode(mode QuoteMode)
- func SetReportTimestamp(report bool)
- func SetSeparatorFromEnv(envVar string)
- func SetStyles(styles *Styles)
- func SetTimeFormat(format string)
- func SetTimeLocation(loc *time.Location)
- type ColorMode
- type Config
- type Context
- func (fb *Context) Any(key string, val any) *T
- func (fb *Context) Anys(key string, vals []any) *T
- func (fb *Context) Bool(key string, val bool) *T
- func (fb *Context) Bools(key string, vals []bool) *T
- func (c *Context) Column(key, path string, lineNumber, column int) *Context
- func (c *Context) Dict(key string, dict *Event) *Context
- func (fb *Context) Dur(key string, val time.Duration) *T
- func (c *Context) Err(err error) *Context
- func (fb *Context) Float64(key string, val float64) *T
- func (fb *Context) Floats64(key string, vals []float64) *T
- func (fb *Context) Int(key string, val int) *T
- func (fb *Context) Ints(key string, vals []int) *T
- func (c *Context) Line(key, path string, lineNumber int) *Context
- func (c *Context) Link(key, url, text string) *Context
- func (c *Context) Logger() *Logger
- func (c *Context) Path(key, path string) *Context
- func (c *Context) Prefix(prefix string) *Context
- func (fb *Context) Str(key, val string) *T
- func (c *Context) Stringer(key string, val fmt.Stringer) *Context
- func (c *Context) Stringers(key string, vals []fmt.Stringer) *Context
- func (fb *Context) Strs(key string, vals []string) *T
- func (fb *Context) Time(key string, val time.Time) *T
- func (fb *Context) Uint64(key string, val uint64) *T
- func (fb *Context) Uints64(key string, vals []uint64) *T
- type Entry
- type Event
- func (e *Event) Any(key string, val any) *Event
- func (e *Event) Anys(key string, vals []any) *Event
- func (e *Event) Bool(key string, val bool) *Event
- func (e *Event) Bools(key string, vals []bool) *Event
- func (e *Event) Column(key, path string, lineNumber, column int) *Event
- func (e *Event) Dict(key string, dict *Event) *Event
- func (e *Event) Dur(key string, val time.Duration) *Event
- func (e *Event) Err(err error) *Event
- func (e *Event) Float64(key string, val float64) *Event
- func (e *Event) Floats64(key string, vals []float64) *Event
- func (e *Event) Int(key string, val int) *Event
- func (e *Event) Ints(key string, vals []int) *Event
- func (e *Event) Line(key, path string, lineNumber int) *Event
- func (e *Event) Link(key, url, text string) *Event
- func (e *Event) Msg(msg string)
- func (e *Event) Msgf(format string, args ...any)
- func (e *Event) Path(key, path string) *Event
- func (e *Event) Prefix(prefix string) *Event
- func (e *Event) Send()
- func (e *Event) Str(key, val string) *Event
- func (e *Event) Stringer(key string, val fmt.Stringer) *Event
- func (e *Event) Stringers(key string, vals []fmt.Stringer) *Event
- func (e *Event) Strs(key string, vals []string) *Event
- func (e *Event) Time(key string, val time.Time) *Event
- func (e *Event) Uint64(key string, val uint64) *Event
- func (e *Event) Uints64(key string, vals []uint64) *Event
- type Field
- type Handler
- type HandlerFunc
- type Level
- type LevelAlign
- type LevelMap
- type Logger
- func (l *Logger) Debug() *Event
- func (l *Logger) Dry() *Event
- func (l *Logger) Error() *Event
- func (l *Logger) Fatal() *Event
- func (l *Logger) Info() *Event
- func (l *Logger) SetColorMode(mode ColorMode)
- func (l *Logger) SetExitFunc(fn func(int))
- func (l *Logger) SetFieldStyleLevel(level Level)
- func (l *Logger) SetFieldTimeFormat(format string)
- func (l *Logger) SetHandler(h Handler)
- func (l *Logger) SetLabels(labels LevelMap)
- func (l *Logger) SetLevel(level Level)
- func (l *Logger) SetLevelAlign(align LevelAlign)
- func (l *Logger) SetOmitEmpty(omit bool)
- func (l *Logger) SetOmitQuotes(omit bool)deprecated
- func (l *Logger) SetOmitZero(omit bool)
- func (l *Logger) SetOutput(out io.Writer)
- func (l *Logger) SetParts(parts ...Part)
- func (l *Logger) SetPrefixes(prefixes LevelMap)
- func (l *Logger) SetQuoteChar(char rune)
- func (l *Logger) SetQuoteChars(openChar, closeChar rune)
- func (l *Logger) SetQuoteMode(mode QuoteMode)
- func (l *Logger) SetReportTimestamp(report bool)
- func (l *Logger) SetStyles(styles *Styles)
- func (l *Logger) SetTimeFormat(format string)
- func (l *Logger) SetTimeLocation(loc *time.Location)
- func (l *Logger) Trace() *Event
- func (l *Logger) Warn() *Event
- func (l *Logger) With() *Context
- type Part
- type ProgressTask
- type ProgressUpdate
- func (fb *ProgressUpdate) Any(key string, val any) *T
- func (fb *ProgressUpdate) Anys(key string, vals []any) *T
- func (fb *ProgressUpdate) Bool(key string, val bool) *T
- func (fb *ProgressUpdate) Bools(key string, vals []bool) *T
- func (fb *ProgressUpdate) Dur(key string, val time.Duration) *T
- func (fb *ProgressUpdate) Float64(key string, val float64) *T
- func (fb *ProgressUpdate) Floats64(key string, vals []float64) *T
- func (fb *ProgressUpdate) Int(key string, val int) *T
- func (fb *ProgressUpdate) Ints(key string, vals []int) *T
- func (u *ProgressUpdate) Send()
- func (fb *ProgressUpdate) Str(key, val string) *T
- func (fb *ProgressUpdate) Strs(key string, vals []string) *T
- func (fb *ProgressUpdate) Time(key string, val time.Time) *T
- func (u *ProgressUpdate) Title(title string) *ProgressUpdate
- func (fb *ProgressUpdate) Uint64(key string, val uint64) *T
- func (fb *ProgressUpdate) Uints64(key string, vals []uint64) *T
- type QuoteMode
- type SpinnerBuilder
- func (fb *SpinnerBuilder) Any(key string, val any) *T
- func (fb *SpinnerBuilder) Anys(key string, vals []any) *T
- func (fb *SpinnerBuilder) Bool(key string, val bool) *T
- func (fb *SpinnerBuilder) Bools(key string, vals []bool) *T
- func (b *SpinnerBuilder) Column(key, path string, lineNumber, column int) *SpinnerBuilder
- func (fb *SpinnerBuilder) Dur(key string, val time.Duration) *T
- func (fb *SpinnerBuilder) Float64(key string, val float64) *T
- func (fb *SpinnerBuilder) Floats64(key string, vals []float64) *T
- func (fb *SpinnerBuilder) Int(key string, val int) *T
- func (fb *SpinnerBuilder) Ints(key string, vals []int) *T
- func (b *SpinnerBuilder) Line(key, path string, lineNumber int) *SpinnerBuilder
- func (b *SpinnerBuilder) Link(key, url, text string) *SpinnerBuilder
- func (b *SpinnerBuilder) Path(key, path string) *SpinnerBuilder
- func (b *SpinnerBuilder) Progress(ctx context.Context, task ProgressTask) *WaitResult
- func (fb *SpinnerBuilder) Str(key, val string) *T
- func (fb *SpinnerBuilder) Strs(key string, vals []string) *T
- func (fb *SpinnerBuilder) Time(key string, val time.Time) *T
- func (b *SpinnerBuilder) Type(s spinner.Spinner) *SpinnerBuilder
- func (fb *SpinnerBuilder) Uint64(key string, val uint64) *T
- func (fb *SpinnerBuilder) Uints64(key string, vals []uint64) *T
- func (b *SpinnerBuilder) Wait(ctx context.Context, task Task) *WaitResult
- type Styles
- type Task
- type WaitResult
- func (fb *WaitResult) Any(key string, val any) *T
- func (fb *WaitResult) Anys(key string, vals []any) *T
- func (fb *WaitResult) Bool(key string, val bool) *T
- func (fb *WaitResult) Bools(key string, vals []bool) *T
- func (w *WaitResult) Debug(msg string) error
- func (fb *WaitResult) Dur(key string, val time.Duration) *T
- func (w *WaitResult) Err() error
- func (fb *WaitResult) Float64(key string, val float64) *T
- func (fb *WaitResult) Floats64(key string, vals []float64) *T
- func (fb *WaitResult) Int(key string, val int) *T
- func (fb *WaitResult) Ints(key string, vals []int) *T
- func (w *WaitResult) Msg(msg string) error
- func (w *WaitResult) Prefix(prefix string) *WaitResult
- func (w *WaitResult) Silent() error
- func (fb *WaitResult) Str(key, val string) *T
- func (fb *WaitResult) Strs(key string, vals []string) *T
- func (fb *WaitResult) Time(key string, val time.Time) *T
- func (fb *WaitResult) Uint64(key string, val uint64) *T
- func (fb *WaitResult) Uints64(key string, vals []uint64) *T
Constants ¶
const ( // DefaultEnvLogLevel is the default environment variable checked for the log level. DefaultEnvLogLevel = "CLOG_LEVEL" // DefaultEnvSeparator is the environment variable checked for the key-value separator. DefaultEnvSeparator = "CLOG_SEPARATOR" )
const ( // LevelTrace is the "trace" level string for [SetLevelFromEnv]. LevelTrace = "trace" // LevelDebug is the "debug" level string for [SetLevelFromEnv]. LevelDebug = "debug" // LevelInfo is the "info" level string. LevelInfo = "info" // LevelDry is the "dry" level string. LevelDry = "dry" // LevelWarn is the "warn" level string. LevelWarn = "warn" // LevelWarning is the "warning" level string (alias for warn). LevelWarning = "warning" // LevelError is the "error" level string. LevelError = "error" // LevelFatal is the "fatal" level string. LevelFatal = "fatal" )
const ErrorKey = "error"
ErrorKey is the default field key used by Event.Err and Context.Err.
Variables ¶
var Default = New(os.Stdout)
Default is the default logger instance.
var DefaultSpinner = spinner.Spinner{ Frames: []string{"🌔", "🌓", "🌒", "🌑", "🌘", "🌗", "🌖", "🌕"}, FPS: spinner.Moon.FPS, }
DefaultSpinner is the default spinner animation.
Functions ¶
func ColorsDisabled ¶
func ColorsDisabled() bool
ColorsDisabled returns true if colours should be disabled. This is true when NO_COLOR is set, ConfigureColorOutput("never") was called, or stdout is not a terminal — unless colours were forced via ConfigureColorOutput("always").
func Configure ¶
func Configure(cfg *Config)
Configure sets up the Default logger with the given configuration. Call this once at application startup.
Note: this respects the CLOG_LEVEL environment variable — it won't reset the level if CLOG_LEVEL was set and cfg.Verbose is false.
func ConfigureColorOutput ¶
func ConfigureColorOutput(mode string)
ConfigureColorOutput sets the colour output mode.
- "auto" — detect terminal capabilities (default behaviour).
- "always" — force colours even when output is not a TTY (overrides NO_COLOR).
- "never" — disable all colours and hyperlinks.
Call this early in your application, before creating custom Styles.
func ConfigureVerbose ¶
func ConfigureVerbose(verbose bool)
ConfigureVerbose enables or disables verbose mode on the Default logger. When verbose is true, it always enables debug logging. When false, it respects the CLOG_LEVEL environment variable if set.
func DefaultMessageStyles ¶
DefaultMessageStyles returns the default per-level message styles (unstyled).
func DefaultValueStyles ¶
DefaultValueStyles returns sensible default styles for common value strings.
func Hyperlink ¶
Hyperlink wraps text in an OSC 8 terminal hyperlink escape sequence. Returns plain text when colours or hyperlinks are disabled globally.
func IsTerminal ¶
func IsTerminal() bool
IsTerminal returns true if stdout is connected to a terminal.
func IsVerbose ¶
func IsVerbose() bool
IsVerbose returns true if verbose/debug mode is enabled on the Default logger. Returns true for both TraceLevel and DebugLevel.
func PathLink ¶
PathLink creates a clickable terminal hyperlink for a file path. The lineNumber parameter is optional — pass 0 to omit line numbers.
func SetColorMode ¶
func SetColorMode(mode ColorMode)
func SetExitFunc ¶
func SetExitFunc(fn func(int))
func SetFieldStyleLevel ¶ added in v0.1.2
func SetFieldStyleLevel(level Level)
func SetFieldTimeFormat ¶ added in v0.1.1
func SetFieldTimeFormat(format string)
func SetHandler ¶
func SetHandler(h Handler)
func SetHyperlinkColumnFormat ¶
func SetHyperlinkColumnFormat(format string)
SetHyperlinkColumnFormat configures the URL format for file+line+column hyperlinks (used by [Column]).
Use {path}, {line}, and {column} (or {col}) as placeholders. Examples:
- vscode://file{path}:{line}:{column}
- idea://open?file={path}&line={line}&column={column}
Default (empty): falls back to the line format.
func SetHyperlinkDirFormat ¶
func SetHyperlinkDirFormat(format string)
SetHyperlinkDirFormat configures the URL format for directory hyperlinks.
Falls back to SetHyperlinkPathFormat if not set.
Use {path} as placeholder.
func SetHyperlinkFileFormat ¶
func SetHyperlinkFileFormat(format string)
SetHyperlinkFileFormat configures the URL format for file-only hyperlinks (used by [Path] and PathLink with lineNumber 0, when the path is not a directory).
Falls back to SetHyperlinkPathFormat if not set.
Use {path} as placeholder.
func SetHyperlinkLineFormat ¶
func SetHyperlinkLineFormat(format string)
SetHyperlinkLineFormat configures the URL format for file+line hyperlinks (used by [Line] and PathLink with lineNumber > 0).
Use {path} and {line} as placeholders. Examples:
- vscode://file{path}:{line}
- idea://open?file={path}&line={line}
- subl://open?url=file://{path}&line={line}
Default (empty): file://{path}
func SetHyperlinkPathFormat ¶
func SetHyperlinkPathFormat(format string)
SetHyperlinkPathFormat configures the generic fallback URL format for any path. This is used when no file-specific or directory-specific format is configured.
Use {path} as placeholder. Examples:
- vscode://file{path}
- idea://open?file={path}
Default (empty): file://{path}
func SetHyperlinksEnabled ¶
func SetHyperlinksEnabled(enabled bool)
SetHyperlinksEnabled enables or disables all hyperlink rendering. When disabled, hyperlink functions return plain text without OSC 8 sequences.
func SetLevelAlign ¶
func SetLevelAlign(align LevelAlign)
func SetLevelFromEnv ¶
func SetLevelFromEnv(envVar string)
SetLevelFromEnv reads the named environment variable and sets the level on the Default logger. Recognised values: trace, debug, info, dry, warn, warning, error, fatal.
func SetLevelLabels ¶
func SetLevelLabels(labels LevelMap)
func SetOmitEmpty ¶
func SetOmitEmpty(omit bool)
func SetOmitQuotes ¶
func SetOmitQuotes(omit bool)
func SetOmitZero ¶
func SetOmitZero(omit bool)
func SetPrefixes ¶
func SetPrefixes(prefixes LevelMap)
func SetQuoteChar ¶
func SetQuoteChar(char rune)
func SetQuoteChars ¶
func SetQuoteChars(openChar, closeChar rune)
func SetQuoteMode ¶
func SetQuoteMode(mode QuoteMode)
func SetReportTimestamp ¶
func SetReportTimestamp(report bool)
func SetSeparatorFromEnv ¶
func SetSeparatorFromEnv(envVar string)
SetSeparatorFromEnv reads the named environment variable and sets the key-value separator on the Default logger's styles.
func SetTimeFormat ¶
func SetTimeFormat(format string)
func SetTimeLocation ¶
Types ¶
type ColorMode ¶
type ColorMode int
ColorMode controls how a Logger determines colour and hyperlink output.
type Config ¶
type Config struct {
// Verbose enables debug level logging and timestamps.
Verbose bool
// Output is the writer to use (defaults to [os.Stdout]).
Output io.Writer
// Styles allows customising the visual styles.
Styles *Styles
}
Config holds configuration options for the Default logger.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context builds a sub-logger with preset fields. Created by Logger.With. Finalise with Context.Logger.
func (*Context) Anys ¶
Anys adds a slice of arbitrary values. Individual elements are highlighted using reflection to determine their type.
func (*Context) Column ¶
Column adds a file path field with a line and column number as a clickable terminal hyperlink. Respects the logger's ColorMode setting.
func (*Context) Dict ¶
Dict adds a group of fields under a key prefix using dot notation. Build the nested fields using Dict to create a field-only Event:
logger := clog.With().Dict("db", clog.Dict().
Str("host", "localhost").
Int("port", 5432),
).Logger()
func (*Context) Dur ¶
Dur adds a time.Duration field.
func (*Context) Line ¶
Line adds a file path field with a line number as a clickable terminal hyperlink. Respects the logger's ColorMode setting.
func (*Context) Link ¶
Link adds a field as a clickable terminal hyperlink with custom URL and display text. Respects the logger's ColorMode setting.
func (*Context) Logger ¶
Logger returns a new Logger with the accumulated fields and prefix. The returned Logger shares the parent's mutex to prevent interleaved output.
func (*Context) Path ¶
Path adds a file path field as a clickable terminal hyperlink. Respects the logger's ColorMode setting.
func (*Context) Stringer ¶
Stringer adds a field by calling the value's String method. No-op if val is nil.
func (*Context) Stringers ¶
Stringers adds a field with a slice of fmt.Stringer values.
type Entry ¶
type Entry struct {
Level Level
Time time.Time // Zero value if timestamps are disabled.
Message string
Prefix string
Fields []Field
}
Entry represents a completed log entry passed to a Handler.
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event represents a log event being constructed. All methods are safe to call on a nil receiver — disabled events (when the log level is below the logger's minimum) are no-ops.
func (*Event) Anys ¶
Anys adds a slice of arbitrary values. Individual elements are highlighted using reflection to determine their type.
func (*Event) Column ¶
Column adds a file path field with a line and column number as a clickable terminal hyperlink. Respects the logger's ColorMode setting.
func (*Event) Dict ¶
Dict adds a group of fields under a key prefix using dot notation. Build the nested fields using Dict to create a field-only Event:
clog.Info().Dict("request", clog.Dict().
Str("method", "GET").
Int("status", 200),
).Msg("handled")
// Output: INF ℹ️ handled request.method=GET request.status=200
func (*Event) Dur ¶
Dur adds a time.Duration field.
func (*Event) Line ¶
Line adds a file path field with a line number as a clickable terminal hyperlink. Respects the logger's ColorMode setting.
func (*Event) Link ¶
Link adds a field as a clickable terminal hyperlink with custom URL and display text. Respects the logger's ColorMode setting.
func (*Event) Msg ¶
Msg finalises the event and writes the log entry. For FatalLevel events, Msg calls os.Exit(1) after writing.
func (*Event) Path ¶
Path adds a file path field as a clickable terminal hyperlink. Respects the logger's ColorMode setting.
func (*Event) Stringer ¶
Stringer adds a field by calling the value's String method. No-op if val is nil.
func (*Event) Stringers ¶
Stringers adds a field with a slice of fmt.Stringer values.
type Handler ¶
type Handler interface {
Log(Entry)
}
Handler processes log entries. Implement this interface to customise how log entries are formatted and output (e.g. JSON logging).
When a Handler is set on a Logger, the Logger handles level checking, field accumulation, timestamps, and mutex locking. The Handler only needs to format and write the entry.
type HandlerFunc ¶
type HandlerFunc func(Entry)
HandlerFunc is an adapter to use ordinary functions as Handler values.
type LevelAlign ¶
type LevelAlign int
LevelAlign controls how level labels are aligned when they have different widths.
const ( // AlignNone disables alignment padding. AlignNone LevelAlign = iota // AlignLeft left-aligns labels (pads with trailing spaces). AlignLeft // AlignRight right-aligns labels (pads with leading spaces). This is the default. AlignRight // AlignCenter center-aligns labels (pads with leading and trailing spaces). AlignCenter )
type LevelMap ¶
LevelMap maps levels to strings (used for labels, prefixes, etc.).
func DefaultLabels ¶
func DefaultLabels() LevelMap
DefaultLabels returns a copy of the default level labels.
func DefaultPrefixes ¶
func DefaultPrefixes() LevelMap
DefaultPrefixes returns a copy of the default emoji prefixes for each level.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is the main structured logger.
func (*Logger) SetColorMode ¶
SetColorMode sets the colour mode for this logger. ColorAuto (default) uses global detection; ColorAlways forces colours and hyperlinks; ColorNever disables them.
func (*Logger) SetExitFunc ¶
SetExitFunc sets the function called by Fatal-level events. Defaults to os.Exit. This can be used in tests to intercept fatal exits.
func (*Logger) SetFieldStyleLevel ¶ added in v0.1.2
SetFieldStyleLevel sets the minimum log level at which field values are styled (coloured). Events below this level render fields as plain text. Defaults to InfoLevel.
func (*Logger) SetFieldTimeFormat ¶ added in v0.1.1
SetFieldTimeFormat sets the format string used for time.Time field values added via Event.Time and Context.Time. Defaults to time.RFC3339.
func (*Logger) SetHandler ¶
SetHandler sets a custom log handler. When set, the handler receives all log entries instead of the built-in pretty formatter.
func (*Logger) SetLabels ¶
SetLabels sets the level labels used in log output. Pass a map from Level to label string (e.g. {WarnLevel: "WARN"}). Missing levels fall back to the defaults.
func (*Logger) SetLevelAlign ¶
func (l *Logger) SetLevelAlign(align LevelAlign)
SetLevelAlign sets the alignment mode for level labels.
func (*Logger) SetOmitEmpty ¶
SetOmitEmpty enables or disables omitting fields with empty values. Empty means nil, empty strings, and nil or empty slices/maps.
func (*Logger) SetOmitQuotes
deprecated
SetOmitQuotes disables quoting of field values that contain spaces or special characters. By default, such values are wrapped in quotes for parseable output.
Deprecated: Use Logger.SetQuoteMode with QuoteNever or QuoteAuto instead.
func (*Logger) SetOmitZero ¶
SetOmitZero enables or disables omitting fields with zero values. Zero means the zero value for any type (0, false, "", nil, etc.). This is a superset of Logger.SetOmitEmpty.
func (*Logger) SetParts ¶
SetParts sets the order in which parts appear in log output. Parts not included in the order are hidden. Parts can be reordered freely. Panics if no parts are provided.
func (*Logger) SetPrefixes ¶
SetPrefixes sets the emoji prefixes used for each level. Pass a map from Level to prefix string. Missing levels fall back to the defaults.
func (*Logger) SetQuoteChar ¶
SetQuoteChar sets the character used to quote field values that contain spaces or special characters. The default (zero value) uses Go-style double-quoted strings via strconv.Quote. Setting a non-zero rune wraps values with that character on both sides (e.g. '\”).
For asymmetric quotes (e.g. '[' and ']'), use Logger.SetQuoteChars.
func (*Logger) SetQuoteChars ¶
SetQuoteChars sets separate opening and closing characters for quoting field values (e.g. '[' and ']', or '«' and '»').
func (*Logger) SetQuoteMode ¶
SetQuoteMode sets the quoting behaviour for field values. QuoteAuto (default) quotes only when needed; QuoteAlways always quotes string/error/default-kind values; QuoteNever never quotes.
func (*Logger) SetReportTimestamp ¶
SetReportTimestamp enables or disables timestamp reporting.
func (*Logger) SetTimeFormat ¶
SetTimeFormat sets the timestamp format string.
func (*Logger) SetTimeLocation ¶
SetTimeLocation sets the timezone for timestamps. Defaults to time.Local.
type Part ¶
type Part int
Part identifies a component of a formatted log line.
const ( // PartTimestamp is the timestamp component. PartTimestamp Part = iota // PartLevel is the level label component. PartLevel // PartPrefix is the emoji prefix component. PartPrefix // PartMessage is the log message component. PartMessage // PartFields is the structured fields component. PartFields )
func DefaultParts ¶
func DefaultParts() []Part
DefaultParts returns the default ordering of log line parts: timestamp, level, prefix, message, fields.
type ProgressTask ¶
type ProgressTask func(context.Context, *ProgressUpdate) error
ProgressTask is a function executed by SpinnerBuilder.Progress. The ProgressUpdate allows updating the spinner's title and fields.
type ProgressUpdate ¶
type ProgressUpdate struct {
// contains filtered or unexported fields
}
ProgressUpdate is a fluent builder for updating a spinner's title and fields during a ProgressTask. Call ProgressUpdate.Title and field methods to build the update, then ProgressUpdate.Send to apply it atomically.
func (*ProgressUpdate) Anys ¶
Anys adds a slice of arbitrary values. Individual elements are highlighted using reflection to determine their type.
func (*ProgressUpdate) Dur ¶
Dur adds a time.Duration field.
func (*ProgressUpdate) Send ¶
func (u *ProgressUpdate) Send()
Send applies the accumulated title and field changes to the spinner atomically.
func (*ProgressUpdate) Str ¶
func (fb *ProgressUpdate) Str(key, val string) *T
Str adds a string field.
func (*ProgressUpdate) Title ¶
func (u *ProgressUpdate) Title(title string) *ProgressUpdate
Title sets the spinner's displayed title.
type SpinnerBuilder ¶
type SpinnerBuilder struct {
// contains filtered or unexported fields
}
SpinnerBuilder configures a spinner before execution.
func Spinner ¶
func Spinner(title string) *SpinnerBuilder
Spinner creates a new SpinnerBuilder with the given title.
func (*SpinnerBuilder) Anys ¶
Anys adds a slice of arbitrary values. Individual elements are highlighted using reflection to determine their type.
func (*SpinnerBuilder) Column ¶
func (b *SpinnerBuilder) Column(key, path string, lineNumber, column int) *SpinnerBuilder
Column adds a file path field with a line and column number as a clickable terminal hyperlink. Uses the Default logger's ColorMode setting.
func (*SpinnerBuilder) Dur ¶
Dur adds a time.Duration field.
func (*SpinnerBuilder) Line ¶
func (b *SpinnerBuilder) Line(key, path string, lineNumber int) *SpinnerBuilder
Line adds a file path field with a line number as a clickable terminal hyperlink. Uses the Default logger's ColorMode setting.
func (*SpinnerBuilder) Link ¶
func (b *SpinnerBuilder) Link(key, url, text string) *SpinnerBuilder
Link adds a field as a clickable terminal hyperlink with custom URL and display text. Uses the Default logger's ColorMode setting.
func (*SpinnerBuilder) Path ¶
func (b *SpinnerBuilder) Path(key, path string) *SpinnerBuilder
Path adds a file path field as a clickable terminal hyperlink. Uses the Default logger's ColorMode setting.
func (*SpinnerBuilder) Progress ¶
func (b *SpinnerBuilder) Progress( ctx context.Context, task ProgressTask, ) *WaitResult
Progress executes the task with a spinner whose title and fields can be updated via the ProgressUpdate builder. This is useful for multi-step operations where the spinner should reflect the current step.
func (*SpinnerBuilder) Str ¶
func (fb *SpinnerBuilder) Str(key, val string) *T
Str adds a string field.
func (*SpinnerBuilder) Type ¶
func (b *SpinnerBuilder) Type(s spinner.Spinner) *SpinnerBuilder
Type sets the spinner animation type.
func (*SpinnerBuilder) Wait ¶
func (b *SpinnerBuilder) Wait(ctx context.Context, task Task) *WaitResult
Wait executes the task with a spinner and returns a WaitResult for chaining. The spinner displays as: <level> <spinner> <title> <fields>.
type Styles ¶
type Styles struct {
FieldDuration *lipgloss.Style // Nil = no styling.
FieldError *lipgloss.Style // Nil = no styling.
FieldNumber *lipgloss.Style // Nil = no styling.
FieldString *lipgloss.Style // Nil = no styling.
FieldTime *lipgloss.Style // Nil = no styling.
KeyDefault *lipgloss.Style
Keys map[string]*lipgloss.Style // Field key name → value style (e.g. "path" → blue).
Levels map[Level]*lipgloss.Style
Messages map[Level]*lipgloss.Style
Separator *lipgloss.Style
SeparatorText string // Separator between key and value (default "=").
Timestamp *lipgloss.Style
Values map[string]*lipgloss.Style // Formatted value → style (e.g. "true" → green).
}
Styles holds lipgloss styles for the logger's pretty output. Pointer fields can be set to nil to disable that style entirely.
type Task ¶
Task is a function executed by SpinnerBuilder.Wait.
type WaitResult ¶
type WaitResult struct {
// contains filtered or unexported fields
}
WaitResult holds the result of a SpinnerBuilder.Wait operation and allows chaining additional fields before finalising the log output.
func (*WaitResult) Anys ¶
Anys adds a slice of arbitrary values. Individual elements are highlighted using reflection to determine their type.
func (*WaitResult) Debug ¶
func (w *WaitResult) Debug(msg string) error
Debug logs at debug level with the given message on success, or at error level on failure. Returns the error.
func (*WaitResult) Dur ¶
Dur adds a time.Duration field.
func (*WaitResult) Err ¶
func (w *WaitResult) Err() error
Err returns the error, logging success at info level or failure at error level using the original spinner title.
func (*WaitResult) Msg ¶
func (w *WaitResult) Msg(msg string) error
Msg logs at info level with the given message on success, or at error level with the original spinner title on failure. Returns the error.
func (*WaitResult) Prefix ¶
func (w *WaitResult) Prefix(prefix string) *WaitResult
Prefix sets a custom emoji prefix for the completion log message.
func (*WaitResult) Silent ¶
func (w *WaitResult) Silent() error
Silent returns just the error without logging anything.