<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Observability on random thoughts</title><link>https://riad.run/tags/observability/</link><description>Recent content in Observability on random thoughts</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Thu, 14 Sep 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://riad.run/tags/observability/feed.xml" rel="self" type="application/rss+xml"/><item><title>Structured Logging in Go with log/slog</title><link>https://riad.run/posts/using-slog/</link><pubDate>Thu, 14 Sep 2023 00:00:00 +0000</pubDate><guid>https://riad.run/posts/using-slog/</guid><description>&lt;p&gt;&lt;em&gt;So you want to use the new shiny structured logging library in golang&lt;/em&gt;&lt;/p&gt;&#10;&#10;&lt;h2 id="logslog"&gt;log/slog&lt;a class="heading-anchor" href="#logslog" aria-label="Link to this section"&gt;#&lt;/a&gt;&#10;&lt;/h2&gt;&lt;p&gt;&lt;code&gt;slog&lt;/code&gt; (a &lt;em&gt;structured&lt;/em&gt; logging library in Go) has been included in the Go standard library starting from version 1.21. While Go already had a logging library, it was considered too simple for most use cases. For starters, it lacked the leveled logging feature. To achieve leveled logging, you had to create multiple loggers with the level as a prefix and direct them all to the same &lt;code&gt;io.Writer&lt;/code&gt;. This package, &lt;a href="https://github.com/spf13/jwalterweatherman" rel="external noopener"&gt;spf13/jwalterweatherman&lt;/a&gt;, accomplishes exactly that. There are also several third-party, excellent logging libraries available for structured logging, such as &lt;a href="https://github.com/rs/zerolog" rel="external noopener"&gt;rs/zerolog&lt;/a&gt;, &lt;a href="https://github.com/uber-go/zap" rel="external noopener"&gt;uber-go/zap&lt;/a&gt;, and &lt;a href="https://github.com/sirupsen/logrus" rel="external noopener"&gt;sirupsen/logrus&lt;/a&gt;, to name a few. Now that structured logging is included in the standard library, let&amp;rsquo;s give it a try.&lt;/p&gt;</description></item></channel></rss>