Kong / go-database-reconciler

Apache License 2.0
5 stars 3 forks source link

Refactor console output #22

Open rainest opened 10 months ago

rainest commented 10 months ago

The original deck design of these libraries had very limited logging. It did not use a logging library, and instead uses a basic wrapper around fmt.Println() to output directly to stdout/stderr. It has a basic global on/off toggle at the library level, though some consumers further add their own wrappers to simulate additional log levels.

To better make these packages a library, we should instead use a logging library or return rich structures to allow consumers to choose their desired log level and behavior. Library features that currently use cprint should instead accept a logger from their instantiator and send log lines to it an appropriate verbosity level, or should eschew logging altogether in favor of returning data that callers can handle as they wish.

There are currently 3 uses of cprint in this library:

The nature of these uses push me towards saying using returned values rather than accepting a logger. The full JSON diffs offered by diff do not readily work with most logging systems, since they're ideally printed over multiple lines for human consumption. These probably require handling (outside the normal logging system) downstream to present effectively. Continuing to print these to stderr makes sense for the deck CLI, but not so much for KIC--KIC does currently dump these to log output at higher verbosity, but it'd probably make more sense to place these in a separate file accessible via the config diagnostic API.

The warning print should probably be handled via initial scans of the input YAML. The deck CLI can scan input to see if basic-auths are present at all and print that warning (though weirdly as I read it we currently only print these on delete actions? idk why--this feature maybe needs further review), and can scan for regexes that don't match the Kong version similarly. KIC simply does not generate the wrong regex type, and has no issues using basic-auth that I know of.

Acceptance:

Tieske commented 10 months ago

Looking at the landscape we have now;

Prior art: shared-go (private repo https://github.com/Kong/shared-go)

There is now also a warning if reading from stdin.

So all uses:

The latter 3 are all stderr type output, only diff produces "user" output.

So my take would be to implement a standard logging mechanism. And only diff would use another for-purpose solution.

czeslavo commented 4 months ago

@rainest Should this be closed given https://github.com/Kong/go-database-reconciler/pull/76 has been merged?