Documentation
¶
Overview ¶
Package log provides a leveled logger with emoji-rich console output for the iterion workflow engine.
Index ¶
- func BlockPreview(s string, max int) string
- func Truncate(s string, max int) string
- func TruncateMiddle(s string, max int) string
- type Format
- type Level
- type Logger
- func (l *Logger) Debug(format string, args ...any)
- func (l *Logger) Error(format string, args ...any)
- func (l *Logger) Info(format string, args ...any)
- func (l *Logger) IsEnabled(level Level) bool
- func (l *Logger) Level() Level
- func (l *Logger) LogBlock(level Level, emoji string, header string, body string)
- func (l *Logger) Logf(level Level, emoji string, format string, args ...any)
- func (l *Logger) Trace(format string, args ...any)
- func (l *Logger) Warn(format string, args ...any)
- func (l *Logger) WithError(err error) *Logger
- func (l *Logger) WithField(key string, value any) *Logger
- func (l *Logger) WithFields(fields map[string]any) *Logger
- func (l *Logger) Writer() io.Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BlockPreview ¶
BlockPreview returns s truncated to max bytes, preserving newlines. If truncated, a "...[truncated]" marker is appended on a new line.
func Truncate ¶
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 ¶
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 Format ¶ added in v0.4.0
type Format int
Format selects between the human-readable console format and the structured JSON format used by the cloud-mode server / runner.
const ( // FormatHuman emits the legacy "HH:MM:SS emoji message" line. This // is the default and preserves byte-for-byte compatibility with // pre-cloud iterion output. FormatHuman Format = iota // FormatJSON emits one JSON object per line; see jsonRecord for the // schema. Suitable for shipping logs into Loki / ELK / CloudWatch. FormatJSON )
type Level ¶
type Level int
Level represents a logging verbosity level.
func ParseLevel ¶
ParseLevel converts a string to a Level. Case-insensitive. Returns LevelInfo if the string is empty.
func ResolveLevel ¶
ResolveLevel resolves the log level from explicit value, env var fallback, and default. The explicit value takes precedence over the env var.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
Logger is a leveled logger that writes either emoji-rich human output (default) or structured JSON. Loggers may carry a fixed set of fields via WithField/WithFields/WithError; the underlying writer and mutex are shared between forks so concurrent log lines never interleave.
func New ¶
New creates a new Logger with the given level and writer in the human-readable format. Equivalent to NewWithFormat(level, w, FormatHuman).
func NewWithFormat ¶ added in v0.4.0
NewWithFormat creates a new Logger with an explicit format.
func (*Logger) LogBlock ¶
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.
In JSON mode, the body is collapsed into the "body" field of the record so downstream tooling sees a single structured event rather than an indented blob.
func (*Logger) Logf ¶
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) WithError ¶ added in v0.4.0
WithError returns a fork carrying the given error under the "error" field. nil errors are a no-op (the fork has no extra context).
func (*Logger) WithField ¶ added in v0.4.0
WithField returns a fork of l carrying the given (key, value) pair in its context. The fork shares the underlying writer and mutex so concurrent writes from parent + child interleave atomically.
func (*Logger) WithFields ¶ added in v0.4.0
WithFields returns a fork of l carrying every (key, value) pair from fields. nil and empty maps return a no-op fork (still safe to call on a nil logger).