#development #golang #logging #reading-list
🔗 Go structured logging with slog
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/slogsubpackage in Go allows you to do that and a whole lot more.
Apart from being able to add levels to log messages,
slogalso 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.
⚠️ This post links to an external website. ⚠️
If this post was enjoyable or useful for you, please share it! If you have comments, questions, or feedback, you can email my personal email. To get new posts, subscribe use the RSS feed.