regclient / regclient

Docker and OCI Registry Client in Go and tooling using those libraries.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Feature] Support slog

Snaipe opened this issue · 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.

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?

What about moving to logr?

Why? What issue are you trying to fix?

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