slog package

The slog package in Go is a structured logging library, offering a way to log messages in a structured form.

official docs (opens in a new tab)

Example of using slog package

package main
 
import (
	"log/slog"
	"os"
)
 
func main() {
	logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
 
	ctxLogger := logger.With("Company", "FollowThePattern")
	// {"time":"2009-11-10T23:00:00Z","level":"INFO","msg":"Learning started!","Company":"FollowThePattern"}
 
	ctxLogger.Info("Learning started!")
}

You can run the code in your browser here (opens in a new tab).