operator-registry icon indicating copy to clipboard operation
operator-registry copied to clipboard

Library code should log only at debug level

Open joelanford opened this issue 4 years ago • 3 comments

In https://github.com/operator-framework/operator-registry/pull/661#discussion_r645271595, there is some discussion about whether or not to discard logs produced by operator-registry libraries.

In the init/render code, we explicitly discard logrus logs because they are unnecessarily verbose on the "happy" path.

IMO, libraries should:

  1. Accept a configurable logger so that callers can choose whether to use it (we're already doing this :+1:) and at what level.
  2. Only log at debug level. In general logging at INFO, WARN, ERROR, etc. levels should be left to callers to implement. Callers own their interfaces to users, not libraries.
  3. If failures occur, return errors and let callers decide how to handle it (perhaps callers log a message, perhaps another code path can be executed).

joelanford avatar Jun 04 '21 04:06 joelanford

Investigate logging libraries to use DEBUG instead of INFO by default. Other solutions involve passing loggers that set their level based on the given context (the logr implementation supports this).

exdx avatar Jun 10 '21 14:06 exdx

As an example, we could swap logrus out for logr in our libraries, and then update opm and other CLIs to use https://github.com/bombsimon/logrusr, which is the logrus implementation of the logr interface.

joelanford avatar Jun 10 '21 19:06 joelanford

Has there been further discussion / a decision made about which direction (i.e defaulting to debug or setting level based on context) to go with?

nsapse avatar May 18 '22 13:05 nsapse