<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/slog-handleroptions-ohnlij1cn" -->

---
title: slog.HandlerOptions | daily.dev
description: This piece walks through Go's slog.HandlerOptions struct, focusing on the AddSource option that adds source code position to log output when creating a...
canonical: https://daily.dev/posts/slog-handleroptions-ohnlij1cn
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: slog.HandlerOptions | daily.dev
og:description: This piece walks through Go's slog.HandlerOptions struct, focusing on the AddSource option that adds source code position to log output when creating a...
og:url: https://daily.dev/posts/slog-handleroptions-ohnlij1cn
og:image: https://api.daily.dev/og/posts/OHnlij1cn.png
og:image:alt: slog.HandlerOptions
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# slog.HandlerOptions

**[Boldly Go](https://daily.dev/sources/boldlygo)** · 2 min read · 2 upvotes · 0 comments

## Summary

This piece walks through Go's slog.HandlerOptions struct, focusing on the AddSource option that adds source code position to log output when creating a JSONHandler or TextHandler. It shows a code example with output demonstrating the source key/value pair, then explains why the author personally skips AddSource in favor of including full stack traces in error objects that get logged. The post closes by pointing to a paid Boot.dev course on logging and observability in Go, with a discount code.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://boldlygo.tech/archive/2026-09-19-slog.handleroptions>

## Questions this post answers

### What does the AddSource option do in Go's slog.HandlerOptions?

AddSource causes the handler to compute the source code position of the log statement and add a source key attribute to the log output. It works with both slog.NewTextHandler and slog.NewJSONHandler by passing HandlerOptions{AddSource: true} when creating the handler, resulting in output like source=/path/to/file.go:12 alongside the log message.

_Developers wiring up structured logging in Go can find deeper slog walkthroughs like this on daily.dev._

### Why might a Go developer skip the AddSource option in slog.HandlerOptions?

Some developers skip AddSource because they already attach full stack traces to their error objects before logging them, making the single source line from AddSource redundant. A stack trace shows the entire call chain across multiple files and functions, giving more debugging context than one file and line number.

_Anyone deciding how to structure Go error logging can dig into tradeoffs like this on daily.dev._

## Similar posts on daily.dev

- [slog Constants](https://daily.dev/posts/slog-constants-sluzy3xoy) · Boldly Go · 20 upvotes · 1 comments
- [slog.Handler](https://daily.dev/posts/slog-handler-z4ruvm49z) · Boldly Go · 4 upvotes · 0 comments
- [Lazy attribute evaluation for JSONHandler](https://daily.dev/posts/lazy-attribute-evaluation-for-jsonhandler-qc9mwy8bm) · Boldly Go · 15 upvotes · 0 comments
- [Handler level](https://daily.dev/posts/handler-level-vt77hf1pi) · Boldly Go · 12 upvotes · 0 comments
- [Issue \#621: Why Go had to hardcode a block on broken certs — Go Weekly](https://daily.dev/posts/issue-621-why-go-had-to-hardcode-a-block-on-broken-certs-go-weekly-nsgai3qmu) · Golang Weekly · 2 upvotes · 0 comments

---

Tags: [#golang](https://daily.dev/tags/golang), [#logging](https://daily.dev/tags/logging), [#observability](https://daily.dev/tags/observability)

[View this post on daily.dev](https://daily.dev/posts/slog-handleroptions-ohnlij1cn)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"slog.HandlerOptions","url":"https://daily.dev/posts/slog-handleroptions-ohnlij1cn","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/slog-handleroptions-ohnlij1cn"},"datePublished":"2026-09-19T16:11:48.229Z","dateModified":"2026-09-19T16:12:08.050Z","description":"This piece walks through Go's slog.HandlerOptions struct, focusing on the AddSource option that adds source code position to log output when creating a...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/a34bbf94f7c8bcbf828174d099f2faa8?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/a34bbf94f7c8bcbf828174d099f2faa8?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Boldly Go","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Boldly Go","logo":"https://media.daily.dev/image/upload/s--0HXlQZhy--/f_auto,q_auto/v1780213594/logos/boldlygo?_a=BAMAMiWQ0","url":"https://daily.dev/sources/boldlygo"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/slog-handleroptions-ohnlij1cn","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"golang,logging,observability","timeRequired":"PT2M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Boldly Go","item":"https://daily.dev/sources/boldlygo"},{"@type":"ListItem","position":3,"name":"slog.HandlerOptions"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/slog-handleroptions-ohnlij1cn#faq","mainEntity":[{"@type":"Question","name":"What does the AddSource option do in Go's slog.HandlerOptions?","acceptedAnswer":{"@type":"Answer","text":"AddSource causes the handler to compute the source code position of the log statement and add a source key attribute to the log output. It works with both slog.NewTextHandler and slog.NewJSONHandler by passing HandlerOptions{AddSource: true} when creating the handler, resulting in output like source=/path/to/file.go:12 alongside the log message. Developers wiring up structured logging in Go can find deeper slog walkthroughs like this on daily.dev."}},{"@type":"Question","name":"Why might a Go developer skip the AddSource option in slog.HandlerOptions?","acceptedAnswer":{"@type":"Answer","text":"Some developers skip AddSource because they already attach full stack traces to their error objects before logging them, making the single source line from AddSource redundant. A stack trace shows the entire call chain across multiple files and functions, giving more debugging context than one file and line number. Anyone deciding how to structure Go error logging can dig into tradeoffs like this on daily.dev."}}]}
```

