Skip to main content
Velo uses a hierarchical logging system where each level represents a different severity. The logger discards messages with a level lower than its configured minimum.

Available log levels

Velo provides seven log levels, defined as Level type in level.go:30-59:
DebugLevel // -1: Fine grained informational events for debugging

Level hierarchy

Levels are ordered by severity from lowest to highest. When you set a minimum level, the logger only processes messages at that level or higher:
  • Setting DebugLevel logs everything
  • Setting InfoLevel (default) filters out debug messages
  • Setting ErrorLevel only logs errors and critical messages
PanicLevel causes the logger to panic after writing the message. FatalLevel calls os.Exit(1) after writing, immediately terminating your application.

Level serialization

JSON format

The Level.JSONField() method (level.go:65-83) returns a zero-allocation string for JSON serialization:
{"level":"info"}
{"level":"error"}
{"level":"fatal"}

Text format

The Level.String() method (level.go:86-105) returns lowercase ASCII representations:
debug
info
warn
error
dpanic
panic
fatal

Parsing levels

Velo accepts both lowercase and uppercase level strings via ParseLevel() (level.go:154-158):
level, err := velo.ParseLevel("info")
level, err := velo.ParseLevel("INFO") // Also valid
The UnmarshalText() method (level.go:118-126) enables configuration via YAML, TOML, or JSON files:
log_level: error

Dynamic level adjustment

The AtomicLevel type (level.go:165-167) allows you to safely change log levels at runtime across all goroutines without restarting your application.

Creating an atomic level

// Initialize at InfoLevel (default)
lvl := velo.NewAtomicLevel()

// Initialize at a specific level
lvl := velo.NewAtomicLevelAt(velo.ErrorLevel)

Changing levels at runtime

logger := velo.NewWithOptions(os.Stdout, velo.Options{
    Level: lvl.Level(),
})

// Later, increase minimum level to reduce log volume
lvl.SetLevel(velo.ErrorLevel)
The AtomicLevel.SetLevel() method (level.go:209-211) uses atomic operations to ensure thread-safe updates. All loggers referencing the same AtomicLevel immediately respect the new threshold.

Checking if a level is enabled

if lvl.Enabled(velo.DebugLevel) {
    logger.Debug("detailed diagnostic info")
}
The Enabled() method (level.go:199-201) returns true if the specified level meets or exceeds the current minimum, allowing you to avoid expensive operations when logs would be discarded.

Special level

Velo internally uses noLevel = 100 (level.go:58) for log entries that should not display a level field. This is an implementation detail not exposed in the public API.

Build docs developers (and LLMs) love