# Structured Logging With Slog

## Metadata
- Author: [[Jonathan Amsterdam]]
- Full Title: Structured Logging With Slog
- Category: #articles
- Summary: The new log/slog package in Go 1.21 allows structured logging using key-value pairs, making it easier for developers to analyze and debug their applications. It integrates seamlessly with the standard logging package and offers features like different log levels and customizable output formats, such as text and JSON. By including structured logging in the standard library, Go aims to provide a common framework that enhances consistency and performance across logging in the ecosystem.
- URL: https://go.dev/blog/slog
## Highlights
- Structured logs use key-value pairs so they can be parsed, filtered, searched, and analyzed quickly and reliably ([View Highlight](https://read.readwise.io/read/01k36tb8cg1fky79g2a2hnmsz8))
- The standard library has had a logging package, `log`, since Go’s initial release over a decade ago. Over time, we’ve learned that structured logging is important to Go programmers. It has consistently ranked high in our annual survey ([View Highlight](https://read.readwise.io/read/01k36tbw7sx16d2g896aqw0e4z))
- Unlike with the `log` package, we can easily add key-value pairs to our output by writing them after the message:
slog.Info("hello, world", "user", os.Getenv("USER"))
The output now looks like this:
2023/08/04 16:27:19 INFO hello, world user=jba ([View Highlight](https://read.readwise.io/read/01k36tg7sd9ah5vfakvzq59tq1))