-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We were previously using the log package as a backend to `logr`. Since 1.21, go supports `slog`, which provides native structured logging. This commit swaps out our `logr` backend to use `slog`. We still want to use `logr`, since it provides a nicer interface imo. There are some compatibility quirks, in particular around log levels. `logr` expects levels of verbosity, whereas in `slog` levels are tied to severity. For now we just negate it.
- Loading branch information
Showing
9 changed files
with
427 additions
and
385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package logging | ||
|
||
import ( | ||
"log/slog" | ||
"os" | ||
|
||
"github.com/go-logr/logr" | ||
"github.com/go-logr/logr/slogr" | ||
) | ||
|
||
type Config struct { | ||
Verbosity int | ||
} | ||
|
||
func New(config *Config) logr.Logger { | ||
logOptions := slog.HandlerOptions{ | ||
AddSource: true, | ||
Level: slog.Level(-config.Verbosity), | ||
} | ||
return slogr.NewLogr(slog.NewJSONHandler(os.Stderr, &logOptions)) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.