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.
Add base level log There are two main requirements for improving the logging of cloudcost-exporter:
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:
slog
as a common logging library to useThere are two three methods added as well:
GetLogLevel
to convert a string to the log levelWriterForOutput
to convert a string to anio.Writer
HandlerForOutput
that takes a string and returns a slog handler for json or text