Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support FromStandardSLogger to wrap a slog.Logger into a hclog.Logger #142

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

magodo
Copy link

@magodo magodo commented Jun 13, 2024

slog.Logger, similar to log.Logger, is a Go 1st class logger type in the standard library. The slog.Logger is also used as an important interface for the OpenTelemetry logging package for Go. The current module has support for log.Logger, so it would be intuitive to have the slog.Logger supported as well.

This PR introduces a new function FromStandardSLogger for wrapping a slog.Logger into a hclog.Logger, similar to the FromStandardLogger. The difference is the interface is a bit different, in that a LoggerOptions is not needed, as those tunnable part are dominated by the slog.Logger itself. Meanwhile, it has an optional parameter lvar, which is a slog.LevelVar. When this is not nil, it is used for supporting the SetLevel method of the returned hclog.Logger (as there is no way to retrieve the slog.LevelVar from a slog.Logger.

There are also two additional consts introduced:

  • SlogLevelTrace: For supporting the hclog.Trace level
  • SlogLevelOff: For supporting the hclog.Off level

The args related feature is implemented natively by the slog attributes.

The name related feature is implemented natively by the slog groups.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant