A focused look at the four built-in constants in Go's slog package: TimeKey, LevelKey, MessageKey, and SourceKey. These constants define the attribute keys automatically added to log entries by the built-in handlers. The post explains what each key represents, when they appear in log output (including the optional SourceKey via AddSource), and how developers can interact with them — either by writing a custom log handler or by using the ReplaceAttr function on HandlerOptions.

2m read timeFrom boldlygo.tech
Post cover image
41.5K Impressions1 Comment