buildpacks / libcnb

A non-opinionated language binding for the Cloud Native Buildpack Buildpack and Extension specifications
Apache License 2.0
31 stars 13 forks source link

Make a configurable Logger interface #124

Closed dmikusa closed 2 years ago

dmikusa commented 2 years ago

Presently, we have log.Logger which is a concrete implementation of a very basic logger. We use this in libcnb to log information. The buildpack calls only debug related methods, with one exception and that is a single call to an info method for logging a warning.

This PR proposes the following changes:

  1. We have a Logger interface that defines debug methods only (more on this later). This can be implemented to control how libcnb logs.
  2. We provide a basic implementation of Logger called PlainLogger that writes to stdout if $BP_LOG_LEVEL=debug or $BP_DEBUG=true. This is in the log module, so it can be bypassed if not needed.
  3. We enable a Logger to be passed in through config options to the main/build/detect functions. Thus a buildpack author can provide their own implementation & control formatting.
  4. We set a style rule that internally libcnb only writes debug level messages. This removes the need for Info/Warn level methods on the interface.
  5. We set a style rule that internally libcnb does not write warnings. Any warning is an error. This is because the warnings that have been used are not messages to end-users, but messages to buildpack authors. Thus making it an error should force buildpack authors to deal with the problem. This should reduce user confusion as they won't see warning messages which they can do nothing about.

Resolves #113

Signed-off-by: Daniel Mikusa dmikusa@vmware.com

samj1912 commented 2 years ago

Also related https://github.com/buildpacks/libcnb/issues/130

@dmikusa-pivotal do we just want to standardize on this interface?