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


Filtering logs by level

Levels In an application, you may wish to log messages only at a certain level or greater. One common configuration is to log messages at Info or higher levels, suppressing debug logging until it is needed. The built-in handlers can be configured with the minimum level to output by setting [HandlerOptions.Level]. The program’s main function typically does this. The default value is LevelInfo. Pretty straight forward, eh? Only want to log Info-and-above inproduction?


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.


slog.HandlerOptions

Now we’ll begin looking at HandlerOptions. Despite the Handler-centricity, this is something we care heavily about as mere users of the slog library. Whenever you instantiate either slog.JSONHandler or slog.TextHandler, you have the option of providing a HandlerOptions object, to tweak the default handler behavior. We’ll look at each of the config options, one at a time. type HandlerOptions type HandlerOptions struct { // AddSource causes the handler to compute the source code position // of the log statement and add a SourceKey attribute to the output.

Get daily content like this in your inbox!

Subscribe