Structured logging in Go with Slog! Golang LOGGING like a 10x ENGINEER

preview_player
Показать описание
In this video, I discuss structured logging in Golang with the new standard library package slog. I dive into how you can set up your logger with Slog Handlers, contextual logging with request IDs, setting up log levels in Go via flags or environment variables and some general best practices of logging in GO.

The aim of this video is to give you an idea of how you can set up logging in Go, and really just to showcase how nice Slog is in the standard lib, no more logging deps!!

Рекомендации по теме
Комментарии
Автор

I like to include an endpoint on my monitor port to be able to set the log level at runtime.

TheQxY
Автор

You don't need the log level map to convert string to log level as slog.Level implements UnmarshalText. You can use flag.TextVar(&opts.logger.level, ...) instead of flag.StringVar and it'll happen automatically (go run ./main.go -log-level debug).

diogolisboa
Автор

Maybe its just me but I find this video really hard to digest and follow. I do like to see how things are being used in a real world example, but it would be much easier if you coded out a best practice example on how to use slog the right way from the start. I believe it would be beneficial to structure the video beforehand to make it easier to follow.

skl