Master Go's slog package vocabulary — Handlers, LogAttrs for performance, level filtering, and log grouping.
0 / 5 completed
1 / 5
At standup, a Go developer asks what the slog package is. What is correct?
log/slog was added to the Go standard library in Go 1.21. It provides a Logger type with levelled, structured logging. The key design is a swappable Handler interface — the stdlib ships with JSONHandler and TextHandler. It supersedes both fmt.Println debugging and third-party loggers like zap or logrus for new projects.
2 / 5
In a PR review, a teammate asks about the Handler interface in slog. What is correct?
slog.Handler is a fully exported interface with four methods: Enabled(context.Context, Level) bool, Handle(context.Context, Record) error, WithAttrs([]Attr) Handler, and WithGroup(string) Handler. Implementing this interface lets you build custom backends (sending logs to OpenTelemetry, Datadog, or a structured file format) while the slog.Logger API remains unchanged.
3 / 5
An incident reveals high allocation rates in a hot logging path. A senior engineer recommends LogAttrs. Why?
slog.Info("msg", "key", val) uses the variadic ...any signature, which boxes each value into an interface{} — causing heap allocations. slog.LogAttrs(ctx, level, msg, slog.String(...), slog.Int(...)) accepts pre-constructed slog.Attr values which are structs, avoiding the interface{} boxing and significantly reducing allocations in hot logging paths.
4 / 5
During a design review, the team asks about log levels in the slog package. What is correct?
slog levels are signed integers: LevelDebug = -4, LevelInfo = 0, LevelWarn = 4, LevelError = 8. Any integer value is valid as a level, and you can define custom levels (e.g. LevelTrace = -8, LevelFatal = 12) by creating a type that satisfies slog.Leveler (the Level() slog.Level method). Handlers use Enabled() to filter by minimum level.
5 / 5
In a code review, a developer calls logger.WithGroup("request"). What does this do?
logger.WithGroup("request") returns a new slog.Logger whose Handler nests all subsequent attributes under the "request" key. In JSON output this produces {"request":{"method":"GET","path":"/","latency_ms":12}} rather than flat top-level keys. This prevents key collisions when different subsystems log attributes with the same names (e.g. both HTTP and DB layers having a "duration" field).
What does the "Go Structured Logging with slog Vocabulary" vocabulary exercise cover?
This exercise tests real IT vocabulary related to go structured logging with slog vocabulary through 5 multiple-choice questions, each built from realistic workplace sentences rather than abstract definitions.
Is this vocabulary exercise free to use?
Yes. Every exercise on CoderSlingo, including this one, is completely free — no account, sign-up, or payment required.
How many questions does this exercise have?
This exercise has 5 questions. Each one shows a real-world sentence or scenario with multiple-choice options and an explanation once you answer.
What happens after I answer a question?
You'll see immediate feedback showing whether your answer was correct, along with a short explanation of why — then a button to move to the next question, and a full results screen at the end.
Can I retry the exercise if I get questions wrong?
Yes. Once you reach the results screen, click "Try again" to reset your answers and go through the exercise from the start as many times as you like.
Do I need to create an account to take this exercise?
No account is needed. Your answers are scored in your browser during the session — nothing is saved to a server, so you can jump straight in.
Is my progress saved if I leave the page?
No — progress within an exercise resets if you navigate away or reload. Each exercise is short enough to complete in a few minutes in one sitting.
Are these vocabulary exercises connected to other topics?
Yes — browse the full vocabulary exercises hub to find related modules covering adjacent IT topics and roles.
How is this different from reading a glossary or blog article?
Exercises like this one are active recall drills — you have to choose the correct term or phrasing yourself, which builds retention faster than passively reading a definition.
Where can I find more vocabulary exercises?
Browse the full Vocabulary exercises hub for hundreds of modules covering Agile, DevOps, security, databases, architecture, and more — organised by IT role and skill.