operator-registry
operator-registry copied to clipboard
Library code should log only at debug level
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:
- Accept a configurable logger so that callers can choose whether to use it (we're already doing this :+1:) and at what level.
- 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.
- 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).
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).
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.
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?