Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

fhofherr/golf

Repository files navigation

Go Logging Facade

The Go Logging Facade (golf) is a thin abstraction over various structured loggers.

Go Reference Go Report Card Coverage Status GitHub tag (latest SemVer pre-release)

golf adheres to semantic versioning. Any breaking changes before version 1.0 or between major versions are listed under Breaking Changes.

Philosophy

This package strives to provide a facade over as many loggers as possible. This allows to keep your code independent from those loggers and to exchange them as needed. By using the golf.Logger interface library code can accept an optional logger which allows it to use whatever logger the calling application uses.

Additionally using different loggers during test execution can be handy, for example if the fact that a message was logged, or its contents need to be asserted.

Versions before 0.3.0 used to define a Logger interfaces that was identical to go-kit's Logger interface. However, I found that calling code almost never checks the error returned by Log. In most cases it is just ignored. Usually this goes along with configuring errcheck to ignore the Logger interface.

In most cases code calling the Log method should not be concerned by an error in the logging library. Ideally the operation should continue to be executed. If it is really necessary to handle an error that occurred during logging, golf provides an Error method. This method allows to access the last error that occurred during logging, if the underlying logger adapter supports it.

Known Adapters

Breaking Changes

The following lists all breaking changes between versions.

  • Replaced golf.NewStdlib with golfstdlib.NewLogger. Made the formatter argument of NewLogger optional.
  • Moved golf.Formatter to golfstdlib.Formatter
  • Moved golf.PlainTextFormatter to golfstdlib.PlainTextFormatter
  • Moved golf.JSONFormatter to golfstdlib.JSONFormatter
  • Moved log.Logger to golf.Logger
  • Moved log.Log to golf.Log
  • Moved log.NewStdlib to golf.NewStdlib
  • Moved log.Formatter to golf.Formatter
  • Moved log.PlainTextFormatter to golf.PlainTextFormatter
  • Moved log.JSONFormatter to golf.JSONFormatter
  • Removed remaining log package

License

Copyright © 2021 Ferdinand Hofherr

Distributed under the MIT License.