-
Book Overview & Buying
-
Table Of Contents
Mastering Go – Third Edition - Third Edition
By :
In this section, we will change the format that the statistics application uses to store its data. This time, the statistics application is going to use the JSON format. Additionally, it uses the cobra package to implement the supported commands.
However, before continuing with the statistics application, we are going to learn more about the slog package.
The log/slog package was added to the standard Go library with Go 1.21 in order to improve the original log package. You can find more information about it at https://pkg.go.dev/log/slog. The main reason for including it in this chapter is that it can create log entries in the JSON format, which is handy when you want to further process log entries.
The code of useSLog.go that illustrates the use of the log/slog package is going to be presented in three parts. The first part is the following:
package main
import (
"fmt"
"log/slog"...