Levels
| Level | Value | Label | Prefix | Description |
|---|---|---|---|---|
Trace | -10 | TRC | π | Finest-grained output, hidden by default |
Debug | -5 | DBG | π | Verbose output, hidden by default |
Info | 0 | INF | βΉοΈ | General operational messages (default minimum level) |
Dry | 2 | DRY | π§ | Dry-run indicators |
Warn | 5 | WRN | β οΈ | Warnings that donβt prevent operation |
Error | 10 | ERR | β | Errors that need attention |
Fatal | 15 | FTL | π₯ | 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.