June 2017
Intermediate to advanced
400 pages
10h 32m
English
The context package now appears in a variety of packages, including the databases and HTTP packages. This recipe will allow you to attach log fields to a context and use them for logging purposes. The idea is that separate methods can attach more fields onto a context as it is passed around, then the final call-site can perform logging and aggregate variables.
This recipe mimics the WithField and WithFields methods found in the logging packages in the previous recipe. These modify a single value stored in the context and also provide the other benefits of using a context: cancellation, timeouts, and thread safety.
Read now
Unlock full access