liveBook · Manning

Log

As explained in Learn Go with Pocket-Sized Projects

A structured log message represents log information as machine-parseable fields with defined meanings rather than as unstructured prose.

Structured logging represents each log event as machine-parseable fields instead of unstructured prose. Programs can then extract values such as level, message, and time for dashboards, error counts, and request-duration measurements. section 4.5

A practical structured logging implementation should:

  • Encode a record such as a level-and-message structure with encoding/json and Marshal. section 4.5
  • Export structure fields so the JSON package can read and write them. section 4.5
  • Prefer a structured logger for concurrent production services rather than the basic log package. section 8.6.3

A structured warning

A JSON event can record a warning that a platform was not scaled up for a request, while preserving fields that programs can parse. section 4.5

{
   "time": "2022-31-10 23:06:30.148845Z",
   "level": "warning",
   "message": "platform not scaled up for request"
}

Inspect a concrete JSON log record with time, level, and message fields. section 4.5

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains JSON fields and Marshal, including exported-field requirements, but defers time validation and broader service implementation.
Examples
Uses a JSON warning containing time, level, and message fields.
What it assumes
Assumes Go programming knowledge while teaching JSON serialization and exported fields through a small logging exercise.
What you can do after
Apply structured logging by encoding records with encoding/json or choosing Go's slog logger for services.
How it connects
Connects structured logging with JSON, dashboards, concurrency, and the slog package.

Also explained in

Compare how 14 books explain log →

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.