The Wayback Machine - https://web.archive.org/web/20200920180549/https://github.com/monzo/slog
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

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 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)

About

Structured logging

Resources

License

Releases

No releases published

Packages

No packages published

Languages

You can’t perform that action at this time.