Before the release of version 1.21, you couldn't set levels for your log messages in Go without either using third-party libraries or writing your own boilerplates. Coming from Python, I've always found this odd, considering that this capability has been in the Python standard library forever. However, it seems like the new log/slog subpackage in Go allows you to do that and a whole lot more.

Apart from being able to add levels to log messages, slog also allows you to emit JSON-structured log messages and group them by certain attributes. The ability to do all this in-house is quite neat and I wanted to take it for a spin. The official documentation on this is on the terser side but still comprehensive. So, here, instead of repeating the same information, I wanted to write something for me that mainly highlights the most common cases.

continue reading on rednafi.com

⚠️ This post links to an external website. ⚠️