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!