Log levels

April 17, 2026

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.

Levels

A Level is an integer representing the importance or severity of a log event. The higher the level, the more severe the event. This package defines constants for the most common levels, but any int can be used as a level.

In the vast majority of cases, all you need to care about are the pre-defined log levels:

const (
	LevelDebug Level = -4
	LevelInfo  Level = 0
	LevelWarn  Level = 4
	LevelError Level = 8
)

And if you ask me, you should virtually never use LevelWarn, but that’s a story for another day.

For now, the important thing to know is that slog.Level is just an integer at heart, which means you can use arbitrary levels, if your application calls for it. The only meaningful significance a level has is that larger values mean “more severe”. So you wouldn’t want to define a custom level of Meh = 2 and OMG = 1. You’d want the more severe level (“OMG”) to have the higher integer value.


Share this

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

Unsure? Browse the archive .

Get daily content like this in your inbox!

Subscribe