regclient icon indicating copy to clipboard operation
regclient copied to clipboard

[Feature] Support slog

Open Snaipe opened this issue 1 year ago • 6 comments

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:

  1. Internally convert all uses of logrus to an slog Logger instead
  2. A new option function would be implemented:
func WithSLog(log *slog.Logger) Opt
  1. For compatibility, WithLog would create a new slog.Logger and wrap the logrus Logger as its slog.Handler, then pass it to WithSLog.

Snaipe avatar May 23 '24 13:05 Snaipe

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.

sudo-bmitch avatar May 23 '24 14:05 sudo-bmitch

What about moving to logr?

shanduur avatar May 27 '24 10:05 shanduur

What about moving to logr?

Why? What issue are you trying to fix?

sudo-bmitch avatar May 27 '24 10:05 sudo-bmitch

@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.

shanduur avatar May 27 '24 19:05 shanduur

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.

Snaipe avatar May 27 '24 19:05 Snaipe

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.

sudo-bmitch avatar May 27 '24 20:05 sudo-bmitch

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?

ydnar avatar Oct 28 '24 21:10 ydnar

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).

sudo-bmitch avatar Oct 28 '24 22:10 sudo-bmitch

Thanks! We've currently implemented a workaround where the regclient dependency is only in non-WASI builds.

ydnar avatar Oct 29 '24 17:10 ydnar

I'll be interested to see wasm projects that use regclient. Feel free to link any real-world use cases.

sudo-bmitch avatar Nov 12 '24 15:11 sudo-bmitch

Thanks!

We use regclient to fetch OCI artifacts containing WebAssembly components: https://pkg.go.dev/go.bytecodealliance.org

ydnar avatar Nov 12 '24 15:11 ydnar