Keyboard shortcuts

Press ← or β†’ to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Levels

LevelValueLabelPrefixDescription
Trace-10TRCπŸ”Finest-grained output, hidden by default
Debug-5DBG🐞Verbose output, hidden by default
Info0INFℹ️General operational messages (default minimum level)
Dry2DRY🚧Dry-run indicators
Warn5WRN⚠️Warnings that don’t prevent operation
Error10ERR❌Errors that need attention
Fatal15FTLπŸ’₯Fatal errors - calls os.Exit(1) after logging

Built-in levels use gaps of 5 between them (except around Dry, which sits at 2), leaving room for custom levels at any position (see Custom Levels).

Setting the Level

// Programmatically
clog.SetLevel(clog.DebugLevel)

// From environment variable (CLOG_LOG_LEVEL is checked automatically on init)
// export CLOG_LOG_LEVEL=debug

Recognised CLOG_LOG_LEVEL values: trace, debug, info, dry, warn, warning, error, fatal, critical.

Setting trace or debug also enables timestamps.

Parsing Levels

ParseLevel converts a string to a Level value (case-insensitive):

level, err := clog.ParseLevel("debug")

Level implements encoding.TextMarshaler and encoding.TextUnmarshaler, so it works directly with flag.TextVar and most flag libraries.

Custom Levels

Define custom levels at any numeric value between the built-in levels. Use RegisterLevel to configure the label, prefix, style, and canonical name.

const SuccessLevel clog.Level = clog.InfoLevel + 1

func init() {
    clog.RegisterLevel(SuccessLevel, clog.LevelConfig{
        Name:   "success",
        Label:  "SCS",
        Prefix: "βœ…",
        Style:  new(lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("2"))),
    })
}

Log with clog.Log(level):

clog.Log(SuccessLevel).Msg("Build completed")
// SCS βœ… Build completed

Custom levels respect level filtering based on their numeric value. ParseLevel, MarshalText, and UnmarshalText all work with registered custom levels.

Use clog.Levels() to iterate all registered levels (built-in and custom) in ascending severity order.