October 14, 2025 | 00:00
Go Context Logger
In Go 1.21, a new logging package was introduced log/slog to provide structured logs built into Go.
What most people are familiar with is the slog.Info and other log levels, such as slog.Error, like the example below:
package main import ( "log/slog" "os" ) func main() { logger := slog.New(slog.NewJSONHandler(os.Stdout, nil)) logger.Info("hello") logger.Error("something bad happened") } This will end up printing:
{"time":"2025-10-14T06:49:41.234716+02:00","level":"INFO","msg":"hello"} {"time":"2025-10-14T06:49:41.234923+02:00","level":"ERROR","msg":"something bad happened"} Context Logging If you look at the package documentation, there is also InfoContext that takes a context and can print items from the context.
Read more