Skip to content

monzo/slog

Folders and files

NameName
Last commit message
Last commit date

Latest commit

b4d5967 Â· Jan 28, 2025

History

67 Commits
Feb 20, 2016
Sep 9, 2020
Nov 14, 2019
Jan 23, 2021
Jan 27, 2025
Jan 27, 2025
Feb 12, 2024
Oct 22, 2024
Jan 22, 2025
Jan 28, 2025
Feb 20, 2016
Nov 14, 2019
Nov 14, 2019
Nov 14, 2019
Jan 22, 2025
Feb 9, 2024
Oct 22, 2024
Sep 30, 2020
Sep 30, 2020
Jan 28, 2025
Jan 22, 2025
Nov 14, 2019

Repository files navigation

slog

Structured logging.

slog is a library for capturing structured log information. In contrast to "traditional" logging libraries, slog:

  • captures a Context for each event
  • captures arbitrary key-value metadata on each log event

slog forwards messages to log by default. But you probably want to write a custom output to make use of the context and metadata. At Monzo, slog captures events both on a per-service and a per-request basis (using the context information) and sends them to a centralised logging system. This lets us view all the logs for a given request across all the micro-services it touches.

Usage

Internally at Monzo, we recommend that users always prefer structured logging where possible. An example of using slog for this would be:

slog.Info(ctx, "Loading widget", map[string]interface{}{
    "stage": "reticulating splines",
})

Errors

slog also provides a shorthand for capturing errors in the form of:

slog.Error(ctx, "Failed to load widget", err)

You may also add metadata to errors captured this way:

slog.Error(ctx, "Failed to load widget", err, map[string]interface{}{
    "user_id": 42,
})

Slog will pick up the first error it finds in the metadata and make it available in event.Error.

Other uses

For backwards-compatibility, slog accepts metadata in the form of map[string]string.

It also accepts format parameters in the style of Printf:

stage := "reticulating splines"
slog.Info(ctx, "Loading widget at stage: %s", stage)

Releases

No releases published

Packages

No packages published

Languages