A logging level categorizes a message by importance, so callers can distinguish debugging details, meaningful events, and failures. section 4.1.2
A practical three-level scale assigns messages according to their significance:
- Debug records developer-focused details such as request paths, processing time, or variable contents; production configurations usually suppress it. section 4.1.2
- Info records meaningful events, such as receiving a payment for a particular account. section 4.1.2
- Error records a failure before recovery, preserving information useful for investigating problems such as an unavailable database or division by zero. section 4.1.2
Represent the finite set of levels with a named Level type and ordered constants. A logger threshold then determines which messages pass: a message is emitted when its level is permitted by the threshold. section 4.1.2 section 4.2.1
Filtering Debug output
A Debugf method returns when the logger threshold is higher than LevelDebug; otherwise it formats and writes the message. Infof and Errorf follow the same level-specific pattern. section 4.2.1
Include the selected level in output when operators need to identify messages while reading or filtering logs. A generic Logf function accepts a level at runtime, useful when application configuration selects the level for one message without changing the global threshold. section 4.4.1 section 4.4.2
const (
// LevelDebug represents the lowest level of log, mostly used for
// debugging purposes.
LevelDebug Level = iota
// LevelInfo represents a logging level that contains information
// deemed valuable.
LevelInfo
// LevelError represents the highest logging level, only to be used
// to trace errors.
LevelError
)
Inspect the compact Go declaration that defines LevelDebug, LevelInfo, and LevelError as ordered constants. section 4.1.2








