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

WBOY
Release: 2024-02-12 16:12:06
forward
1120 people have browsed it

如何在 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()
Copy after login

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!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!