[Feature] Support slog
Current Behavior
Structured logging has now been standardized in the log/slog package. API consumers that use slog need to allocate a separate logrus logger to use with regclient, which is fairly inconvenient.
Expected Behavior
There should be an Opt to specify the slog.Logger to use.
Example Solution
Fixing this would mean:
- Internally convert all uses of logrus to an slog Logger instead
- A new option function would be implemented:
func WithSLog(log *slog.Logger) Opt
- For compatibility,
WithLogwould create a new slog.Logger and wrap the logrus Logger as its slog.Handler, then pass it to WithSLog.
regclient maintains support for at least 3 releases of Go, which means 1.20 - 1.22 right now. This would need to wait until 1.23 is released and 1.20 support is dropped.
What about moving to logr?
@sudo-bmitch the same reasoning as in the issue. Regclient is dependent on logrus. If I am using any other logger in my app, I need to either switch the whole application to logrus, or write a compatibility code that will allow common configuration between logrus and insert other logging library name. Using generic logging interface (e.g. slog or logr), regclient can be decoupled from a particular logging library.
The main difference is that slog is part of the standard library, while logr isn't, and it doesn't seem worth to provide APIs for it. It doesn't seem compelling to add more alternate logging interfaces when consolidating existing code to start using the standard library more seems like a somewhat obvious path forward.
In addition to removing dependencies by shifting to the standard library in the future, it's a bit unusual for an application to tightly bind its logging to that of the libraries that it uses. A majority of users would leave logging completely disabled (the default) and just check the error responses. In a shift to slog I'm expecting to remove a number of logging points, and focus on http tracing that may be needed to debug low level issues.
Just got bit by the logrus dependency using this module (thanks!) with GOOS=wasip1. Logrus itself hasn’t been updated in 18 months.
Now that Go 1.23 is released, would you consider dropping the logrus dependency?
Adding log/slog support is definitely on the list. Deprecating logrus will take time since people need the opportunity to upgrade their own tools without immediate breaking changes.
Edit: it will likely be possible to move the logrus dependency into a file that isn't included in wasi builds. Having some kind of wasi test case would be needed to ensure that works, unless you are only running one of the included commands (regctl, regsync, regbot).
Thanks! We've currently implemented a workaround where the regclient dependency is only in non-WASI builds.
I'll be interested to see wasm projects that use regclient. Feel free to link any real-world use cases.
Thanks!
We use regclient to fetch OCI artifacts containing WebAssembly components: https://pkg.go.dev/go.bytecodealliance.org