liveBook · Manning

Logging level

As explained in Learn Go with Pocket-Sized Projects

A log level is a category indicating the importance or severity of a recorded log message.

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

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Defines ordered levels and implements threshold checks, output decoration, and runtime selection, without detailing a larger severity taxonomy.
Examples
Uses Debug, Info, and Error messages, threshold-filtered Debugf calls, colored console inspection, and table-driven logger tests.
What you can do after
Build a Go logger with ordered levels, threshold filtering, level-specific methods, and runtime-selected logging.
How it connects
Connects logging levels with enumerations, logger thresholds, formatted output, configuration, and testing.

Also explained in

Compare how 9 books explain logging level →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.