{"id":290,"date":"2026-04-29T09:00:00","date_gmt":"2026-04-29T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/"},"modified":"2026-10-10T21:20:59","modified_gmt":"2026-10-10T15:50:59","slug":"go-structured-logging-slog","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/","title":{"rendered":"Go Structured Logging with log\/slog"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Go structured logging records events as key and value pairs, so both people and tools can read your logs easily. In this post, you will use the <code>log\/slog<\/code> package to write text and JSON logs. You will also filter by level and attach request details. Also, each idea comes with a short example.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Above all, logs matter in servers, like the one from <a href=\"https:\/\/smitabharat.com\/blog\/go-http-server-beginners\/\">the Go HTTP server tutorial<\/a>. We will also attach a request ID, an idea you met in <a href=\"https:\/\/smitabharat.com\/blog\/go-context-beginners-guide\/\">Go context for beginners<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is Go Structured Logging?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A plain log line is just a sentence, such as &#8220;user asha logged in&#8221;. That is easy to read but hard to search. Structured logs, however, keep each detail in its own named field.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, think of a messy note versus a filled-in form. With a form, you can instantly find every row where <code>user=asha<\/code>. Since Go 1.21, the standard library includes <code>log\/slog<\/code> for exactly this job, so you need no extra package.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Your First slog Message<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>slog.Info(\"server started\", \"port\", 8080)\n\/\/ 2026\/08\/21 09:00:00 INFO server started port=8080<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">First of all, the first argument is the message. After that, arguments come in pairs: a key, then its value. By default, <code>slog<\/code> writes through the classic <code>log<\/code> package, so the line starts with the date.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Text and JSON Handlers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In short, a handler decides how each record looks and where it goes. The diagram below shows one log call flowing through a logger into two different handlers.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-structured-logging-slog-diagram-1024x640.png\" alt=\"Go Structured Logging diagram showing one log call turned into a record and written by text and JSON handlers\" class=\"wp-image-271\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-structured-logging-slog-diagram-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-structured-logging-slog-diagram-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-structured-logging-slog-diagram-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-structured-logging-slog-diagram-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-structured-logging-slog-diagram-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><em>The logger builds a record with a level, message and attributes, and the handler turns it into text or JSON.<\/em><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>text := slog.New(slog.NewTextHandler(os.Stdout, nil))\ntext.Info(\"user login\", \"user\", \"asha\", \"attempt\", 1)\n\/\/ time=... level=INFO msg=\"user login\" user=asha attempt=1\n\njsonLog := slog.New(slog.NewJSONHandler(os.Stdout, nil))\njsonLog.Info(\"order placed\", \"order_id\", 1042, \"amount\", 499.5)\n\/\/ {\"time\":\"...\",\"level\":\"INFO\",\"msg\":\"order placed\",\"order_id\":1042,\"amount\":499.5}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Also, the time is shortened to dots here. Use the text handler on your laptop, because it is easy to read. In production, prefer JSON, since log tools such as Grafana Loki or Elasticsearch can search every field.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Log Levels in Go Structured Logging<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Level<\/th><th>Use it for<\/th><\/tr><\/thead><tbody><tr><td>Debug<\/td><td>Details only developers need<\/td><\/tr><tr><td>Info<\/td><td>Normal events, such as a server start<\/td><\/tr><tr><td>Warn<\/td><td>Something odd that did not fail<\/td><\/tr><tr><td>Error<\/td><td>A failure that needs attention<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>jsonLog.Debug(\"not shown by default\")\n\nopts := &amp;slog.HandlerOptions{Level: slog.LevelDebug}\ndebugLog := slog.New(slog.NewJSONHandler(os.Stdout, opts))\ndebugLog.Debug(\"cache miss\", \"key\", \"user:7\")\n\/\/ {\"time\":\"...\",\"level\":\"DEBUG\",\"msg\":\"cache miss\",\"key\":\"user:7\"}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">By default, handlers drop Debug messages. So pass <code>HandlerOptions<\/code> with a lower level when you need more detail, for example while hunting a bug.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Adding Context with With and Group<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>reqLog := jsonLog.With(\"request_id\", \"abc-123\")\nreqLog.Warn(\"slow query\", \"ms\", 950)\n\/\/ {\"time\":\"...\",\"level\":\"WARN\",\"msg\":\"slow query\",\"request_id\":\"abc-123\",\"ms\":950}\n\njsonLog.Info(\"request\", slog.Group(\"http\", \"method\", \"GET\", \"status\", 200))\n\/\/ {\"time\":\"...\",\"level\":\"INFO\",\"msg\":\"request\",\"http\":{\"method\":\"GET\",\"status\":200}}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">In particular, <code>With<\/code> returns a new logger that adds the same fields to every line. As a result, all logs for one request share its ID, which makes tracing easy. Meanwhile, <code>Group<\/code> nests related fields under one key.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Structured Logging in an HTTP Handler<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>func helloHandler(w http.ResponseWriter, r *http.Request) {\n\tstart := time.Now()\n\tlog := slog.With(\"method\", r.Method, \"path\", r.URL.Path)\n\tlog.Info(\"request received\")\n\n\tw.Write([]byte(\"hello\"))\n\n\tlog.Info(\"request done\", \"duration_ms\", time.Since(start).Milliseconds())\n}\n\/\/ time=... level=INFO msg=\"request received\" method=GET path=\/hello\n\/\/ time=... level=INFO msg=\"request done\" method=GET path=\/hello duration_ms=0<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With Go structured logging, each handler builds a small logger that already knows the method and path. So every line from that request carries the same fields without repeating them. Also, in a real app, you would add the request ID here too. Then, when a user reports a problem, search for that ID to see the whole request story.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Setting the Default Logger<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>slog.SetDefault(jsonLog)\nslog.Info(\"now JSON by default\")\n\/\/ {\"time\":\"...\",\"level\":\"INFO\",\"msg\":\"now JSON by default\"}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, call <code>SetDefault<\/code> once in <code>main<\/code>. Then every package that uses <code>slog.Info<\/code> gets the same format. Indeed, this is the easiest way to switch a whole app to Go structured logging.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with Go Structured Logging<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Problem you see<\/th><th>Why it happens<\/th><th>How to fix it<\/th><\/tr><\/thead><tbody><tr><td><code>!BADKEY=<\/code> appears in the output<\/td><td>Because a key or value is missing in the pairs.<\/td><td>So always pass key, value, key, value.<\/td><\/tr><tr><td>Debug lines never show<\/td><td>Because the default level is Info.<\/td><td>So set <code>Level: slog.LevelDebug<\/code>.<\/td><\/tr><tr><td>Passwords appear in logs<\/td><td>Because secret fields were logged directly.<\/td><td>So never log secrets, or mask them.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Also, run <code>go vet<\/code> to catch the first problem early. It reports errors such as &#8220;call to slog.Info missing a final value&#8221;. Logging questions also come up in backend interviews, so practise with my <a href=\"https:\/\/smitabharat.com\/blog\/go-lang-interview-questions-and-answers\/\">Go interview questions and answers<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages come straight from the Go team, so they stay accurate and up to date.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/pkg.go.dev\/log\/slog\">log\/slog package documentation<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/blog\/slog\">Go blog: Structured Logging with slog<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Go structured logging stores details as key and value pairs.<\/li>\n\n\n\n<li>The standard <code>log\/slog<\/code> package has text and JSON handlers.<\/li>\n\n\n\n<li>Levels are Debug, Info, Warn and Error, with Info as the default.<\/li>\n\n\n\n<li><code>With<\/code> adds shared fields, and <code>Group<\/code> nests related ones.<\/li>\n\n\n\n<li>Call <code>slog.SetDefault<\/code> once to set the format for the whole app.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As a result, your app now writes clear, searchable logs. Next, we will configure it without changing code by reading environment variables.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next lesson: <a href=\"https:\/\/smitabharat.com\/blog\/go-environment-variables-config\/\">Go Environment Variables for App Configuration<\/a><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Go structured logging records events as key and value pairs, so both people and tools can read your logs easily. In this post, you&hellip;<\/p>\n","protected":false},"author":1,"featured_media":270,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[11,56,23,21],"swapz_series":[],"class_list":["post-290","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-go-lang","tag-go-logging","tag-go-tutorial","tag-golang-basics"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Structured Logging with log\/slog Explained<\/title>\n<meta name=\"description\" content=\"Learn Go structured logging with log\/slog: text and JSON handlers, log levels, adding context with With and Group, and a default logger.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Structured Logging with log\/slog Explained\" \/>\n<meta property=\"og:description\" content=\"Learn Go structured logging with log\/slog: text and JSON handlers, log levels, adding context with With and Group, and a default logger.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-04-29T03:30:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-10T15:50:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-structured-logging-slog-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-structured-logging-slog\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-structured-logging-slog\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Structured Logging with log\\\/slog\",\"datePublished\":\"2026-04-29T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-structured-logging-slog\\\/\"},\"wordCount\":707,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-structured-logging-slog\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-structured-logging-slog-featured.png\",\"keywords\":[\"Go Lang\",\"Go Logging\",\"Go Tutorial\",\"Golang Basics\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-structured-logging-slog\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-structured-logging-slog\\\/\",\"name\":\"Go Structured Logging with log\\\/slog Explained\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-structured-logging-slog\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-structured-logging-slog\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-structured-logging-slog-featured.png\",\"datePublished\":\"2026-04-29T03:30:00+00:00\",\"dateModified\":\"2026-10-10T15:50:59+00:00\",\"description\":\"Learn Go structured logging with log\\\/slog: text and JSON handlers, log levels, adding context with With and Group, and a default logger.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-structured-logging-slog\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-structured-logging-slog\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-structured-logging-slog\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-structured-logging-slog-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-structured-logging-slog-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Structured Logging featured image: cards for log levels, the JSON handler and shared fields\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-structured-logging-slog\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Structured Logging with log\\\/slog\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Structured Logging with log\/slog Explained","description":"Learn Go structured logging with log\/slog: text and JSON handlers, log levels, adding context with With and Group, and a default logger.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/","og_locale":"en_US","og_type":"article","og_title":"Go Structured Logging with log\/slog Explained","og_description":"Learn Go structured logging with log\/slog: text and JSON handlers, log levels, adding context with With and Group, and a default logger.","og_url":"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-04-29T03:30:00+00:00","article_modified_time":"2026-10-10T15:50:59+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-structured-logging-slog-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Structured Logging with log\/slog","datePublished":"2026-04-29T03:30:00+00:00","dateModified":"2026-10-10T15:50:59+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/"},"wordCount":707,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-structured-logging-slog-featured.png","keywords":["Go Lang","Go Logging","Go Tutorial","Golang Basics"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/","url":"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/","name":"Go Structured Logging with log\/slog Explained","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-structured-logging-slog-featured.png","datePublished":"2026-04-29T03:30:00+00:00","dateModified":"2026-10-10T15:50:59+00:00","description":"Learn Go structured logging with log\/slog: text and JSON handlers, log levels, adding context with With and Group, and a default logger.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-structured-logging-slog-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-structured-logging-slog-featured.png","width":2400,"height":1260,"caption":"Go Structured Logging featured image: cards for log levels, the JSON handler and shared fields"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-structured-logging-slog\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Structured Logging with log\/slog"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/290","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=290"}],"version-history":[{"count":2,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/290\/revisions"}],"predecessor-version":[{"id":315,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/290\/revisions\/315"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/270"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=290"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=290"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=290"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=290"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}