Yesterday we saw that slog uses handlers to process/record logs. But what exactly does it process? Records!
Overview
…
A log record consists of a time, a level, a message, and a set of key-value pairs, where the keys are strings and the values may be of any type. As an example,
slog.Info("hello", "count", 3)creates a record containing the time of the call, a level of Info, the message “hello”, and a single pair with key “count” and value 3.
When you use the log/slog package, you’re basically building records by (usually) calling level-specific methods, passing a message, and potentially key/value/value pairs. This record is then what’s passed to the handler(s) you’ve configured. The handler(s) then typically format the record as plain text, as JSON, or to send to your cloud logging API.