grafana / cloudcost-exporter

Prometheus Exporter for Cloud Provider agnostic cost metrics
Apache License 2.0
30 stars 1 forks source link

Feat/add leveled logger interface #197

Closed Pokom closed 3 months ago

Pokom commented 3 months ago

Add base level log There are two main requirements for improving the logging of cloudcost-exporter:

  1. Structured logging with consistent labels across providers and collectors
  2. Ability to define a log level and runtime that limits the logs

There are no shortage of existing Go packages that could have been to meet the first requirement, such that:

However each of these comes with tradeoffs and then yet dependency to maintain. The go team released slog officially in go 1.21, which provides a structured logging implemention as part of the standard library. This makes it a prime candidate to immediate meet the first requirement.

The second requirement(levels) is a bit more nuanced since the slog is thin implementation. The go team provides a reference example to use: https://pkg.go.dev/log/slog@master#example-Handler-LevelHandler. This PR aims to meet both requirements by:

  1. Adding slog as a common logging library to use
  2. Creating a levels implementation that allows us to toggle the emitted level

There are two three methods added as well: