Home >Backend Development >Golang >How to retrieve log level using 'slog' package in Go?

How to retrieve log level using 'slog' package in Go?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBforward
2024-02-12 16:12:061274browse

如何在 Go 中使用“slog”包检索日志级别?

Question content

I'm currently developing a project using Go and I've set up logging using the "slog" package but I can't figure out how to do it programmatically Retrieve the current log level.

I want to use something like:

lvl := slog.GetLogLevel()

But the aove function does not exist. Is it possible to retrieve the current log level programmatically?

Workaround

You can use slog.Default().Enabled() to check if you want to log a certain level. The log level is retained within the handler, and no method is provided to obtain handler options.

The above is the detailed content of How to retrieve log level using 'slog' package in Go?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete