Intro to slog levels

April 3, 2026

By default, the log/slog package supports four log levels: Debug, Info, Warn, and Error, each of which has matching logger methods:

Overview

The Info top-level function calls the Logger.Info method on the default Logger. In addition to Logger.Info, there are methods for Debug, Warn and Error levels. Besides these convenience methods for common levels, there is also a Logger.Log method which takes the level as an argument. Each of these methods has a corresponding top-level function that uses the default logger.

But if you need custom levels (Trace? Notice? Fatal? ReallyFrigginImportantMan!?) you can define those for your application, and use the generic logger.Log method. You’ll likely never need custom levels, but if you do, they’re there. And we’ll get into all those nitty gritty details when the time comes.


But if you don’t need all the nitty gritty details, and want to hit the ground running a bit faster than I get through logging in this series, I have another resource I’d like to share with you!

I have partnered with Boot.dev as the author of their brand new course: Learn Logging and Observability in Go. In this course, I take you through how to set up logging, Prometheus, and OpenTelemetry in a real web application.

The course isn’t as in-depth as I get in this free email series—it would be a multi-volume book if I did! But it’s a lot more practical as an intro to the topic. If you use code JHALL at checkout, you’ll also save 25% on your first payment, for up to a year of Boot.dev’s great courses!


Share this

Direct to your inbox, daily. I respect your privacy .

Unsure? Browse the archive .

Related Content


Log levels

I'm launching a new live course: **Idiomatic Testing in Go**. The course begins May 5. Early-bird pricing is in effect until April 28. Why Go avoids assert libraries Better alternatives to mocks Make writing tests fun! See pricing & reserve → log/slog provides some rather sophisticated capabilities around log levels. We’ll get into it, but the good news is, you don’t need to care about how sophisticated it can get, if you don’t care.


Logging common fields

It’s common that you’ll want to include certain attributes in all logs in an application or component. log/slog makes this pretty easy. Overview … Some attributes are common to many log calls. For example, you may wish to include the URL or trace identifier of a server request with all log events arising from the request. Rather than repeat the attribute with every log call, you can use Logger.With to construct a new Logger containing the attributes:


Handler configuration

The default slog handlers are quite configurable. Overview … Both TextHandler and JSONHandler can be configured with HandlerOptions. There are options for setting the minimum level (see Levels, below), displaying the source file and line of the log call, and modifying attributes before they are logged. While HandlerOptions only exposes three fields: AddSource bool Level Leveler ReplaceAttr func(groups []string, a Attr) Attr The last one provides an immense amount of flexibility, letting you filter, replace, or augment log key/value pairs as they are processed.

Get daily content like this in your inbox!

Subscribe