Closed nhi-vanye closed 1 year ago
hi @nhi-vanye
There are two ways to limit the log level to be recorded in slog
:
[]level
to restrict logging to specified level logsmax level
to limit the maximum log levelIn the next version, I will provide some convenient methods to quickly use two methods:
// limit max log level, will log: panic ~ info level logs
h := handler.ConsoleWithLevel(slog.Info)
functions:
// ConsoleWithLevel create new ConsoleHandler and with max log level
func ConsoleWithLevel(level slog.Level) *ConsoleHandler
// ConsoleWithLevels create new ConsoleHandler and with limited log levels
func ConsoleWithLevels(levels []slog.Level) *ConsoleHandler
Thank you for very quick response.
I might consider changing the name to be ConsoleWithMaxLevel()
to more closely match the behaviour as I think there's a good use-case for a corresponding ConsoleWithMinLevel()
. That would make it very easy to separate production from debug logs with multiple handlers off a single Logger...
On every logging system I've used across many languages if you set the log level to be Info, you also get Warning, Error, Fatal etc.
Not so with slog.
If I do
handler.NewConsoleHandler(slog.Levels{slog.InfoLevel})
I just get Info messages...So I'm expected to build by own list ? That's really annoying to do programmatically for no value that I can see...