Each handler has an optional Level value, which controls which logs to drop, and which to actually log:
type HandlerOptions
type HandlerOptions struct { … // Level reports the minimum record level that will be logged. // The handler discards records with lower levels. // If Level is nil, the handler assumes LevelInfo. // The handler calls Level.Level for each record processed; // to adjust the minimum level dynamically, use a LevelVar. Level Leveler
For common usage, you’ll simply set this to one of the defined slog.Level values: Debug, Info, Warn, or Error.
But notice that the type of this field isn’t slog.Level, it’s slog.Leveler, which is actually an interface type. We’ll talk in more detail about how to take advantage of this soon, but it’s quite handy because it allows you to easily change the handler’s level dynamically at runtime, by passing a value that satisfies the slog.Leveler interface. This allows you to change the handler’s level via a database option, or by reading a config file dynamically at runtime, or any other number of ways.