-
Notifications
You must be signed in to change notification settings - Fork 659
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
options.Logger is incompatible to slog logger #898
Comments
We covered this in the fortnightly etcd triage meeting. In #509, the decision was to implement a logger interface compatible with I'm torn because implementing a bridge/wrapper struct for every existing logger doesn't make sense and may quickly become an issue. However, The bridge/wrapper is pretty simple: import (
"fmt"
"log/slog"
bolt "go.etcd.io/bbolt"
)
type logger struct {
*slog.Logger
}
func (l logger) Debug(v ...interface{}) {}
func (l logger) Debugf(format string, v ...interface{}) { l.Logger.Debug(fmt.Sprintf(format, v...)) }
func (l logger) Error(v ...interface{}) {}
func (l logger) Errorf(format string, v ...interface{}) { l.Logger.Error(fmt.Sprintf(format, v...)) }
func (l logger) Info(v ...interface{}) {}
func (l logger) Infof(format string, v ...interface{}) { l.Logger.Info(fmt.Sprintf(format, v...)) }
func (l logger) Warning(v ...interface{}) {}
func (l logger) Warningf(format string, v ...interface{}) { l.Logger.Warn(fmt.Sprintf(format, v...)) }
func (l logger) Fatal(v ...interface{}) {}
func (l logger) Fatalf(format string, v ...interface{}) { l.Logger.Error(fmt.Sprintf(format, v...)) }
func (l logger) Panic(v ...interface{}) {}
func (l logger) Panicf(format string, v ...interface{}) { l.Logger.Error(fmt.Sprintf(format, v...)) }
func main() {
lg := logger{slog.Default()}
db, err := bolt.Open("test.db", 0600, &bolt.Options{Logger: lg})
...
} Note that we only use the I believe it would make more sense to document rather than implement it. What do you think, @ahrtr? |
We don't want to manage any specific logger, nor their configuration. It's the reason why we only expose an interface. Also exp/slog was experimental when we started to add logger into bbolt. But it's part of the golang std lib (starting from go1.21) now. It's definitely better to enhance the document at least at https://pkg.go.dev/go.etcd.io/bbolt@v1.4.0#Logger. If the community pushes hard, then I I do not object to adding thin wrappers for |
Here's one vote for it ;) |
Are you voting for below comment? :)
|
I did but to be honest, I followed the suggestion here and just implemented the logger interface. It's ok. |
I am using the slog logger and wanted to enable the new
Options.Logger
feature, which fails:Compilation fails:
So, in order to be able to use my existing logger setup, I'd have to implement a
bolt.Logger
wrapper around the slog logger.I'd appreciate it, if slog would be supported directly.
best,
Tom
The text was updated successfully, but these errors were encountered: