<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Logging on random thoughts</title><link>https://riad.run/tags/logging/</link><description>Recent content in Logging 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/logging/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><item><title>Trace Logging in Golang</title><link>https://riad.run/posts/trace-in-golang/</link><pubDate>Sun, 20 Aug 2023 00:00:00 +0000</pubDate><guid>https://riad.run/posts/trace-in-golang/</guid><description>&lt;p&gt;&lt;em&gt;Disclaimer: This article is not about &lt;code&gt;runtime/trace&lt;/code&gt; package or trace profiling functionalities.&lt;/em&gt;&lt;/p&gt;&#10;&lt;p&gt;Tracing is used to observe code execution paths. If you log something in a function and you see that output in the log file, then you know that the function has been executed. There is a log level defined in different logger implementations called &lt;code&gt;TRACE&lt;/code&gt;, which is the lowest log level in most loggers. The log won&amp;rsquo;t be present in the production environment, but when debugging, you&amp;rsquo;ll receive the traces. This is useful in situations where a debugger is not accessible.&lt;/p&gt;</description></item></channel></rss>