caas-team / sparrow

A monitoring tool to gather infrastructure network information
Apache License 2.0
6 stars 4 forks source link

feat: logging verbosity #87

Closed lvlcn-t closed 8 months ago

lvlcn-t commented 8 months ago

Motivation

To change the logging verbosity dynamically on startup.

Closes #28

Changes

After some feedback I've simplified it to just be configurable with an environment variable on startup.

If we wanted to have it as flag/config field we can use commit https://github.com/caas-team/sparrow/commit/5d8c823aad5f1d8afb8926cb39b48f9cb302975e

For additional information look at the commits.

Tests done

I've added unit tests for the logger package:

Logs without LOG_LEVEL:

$ go run main.go run --config .tmp/start-config.yaml 
Using config file: .tmp/start-config.yaml
{"time":"2024-01-24T15:07:27.257247904+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/cmd.NewCmdRun.run.func1","file":"/home/installadm/dev/github/sparrow/cmd/run.go","line":81},"msg":"Running sparrow"}
{"time":"2024-01-24T15:07:27.257356895+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow.(*Sparrow).api.func1","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/api.go","line":81},"msg":"Serving Api","addr":":8080"}
{"time":"2024-01-24T15:07:27.257446323+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/config.(*FileLoader).Run","file":"/home/installadm/dev/github/sparrow/pkg/config/file.go","line":47},"msg":"Reading config from file","file":"./.tmp/run-config.yaml"}
{"time":"2024-01-24T15:07:27.257515689+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow/targets.(*gitlabTargetManager).Reconcile","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/targets/gitlab.go","line":80},"msg":"Starting global gitlabTargetManager reconciler"}
{"time":"2024-01-24T15:07:27.257754297+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/checks/latency.(*Latency).Run","file":"/home/installadm/dev/github/sparrow/pkg/checks/latency/latency.go","line":91},"msg":"Starting latency check","interval":"20s"}
{"time":"2024-01-24T15:07:27.257791226+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).Run","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":89},"msg":"Starting healthcheck","interval":"20s"}

Logs with LOG_LEVEL=DEBUG:

$ go run main.go run --config .tmp/start-config.yaml 
Using config file: .tmp/start-config.yaml
{"time":"2024-01-24T15:06:19.787770563+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/cmd.NewCmdRun.run.func1","file":"/home/installadm/dev/github/sparrow/cmd/run.go","line":81},"msg":"Running sparrow"}
{"time":"2024-01-24T15:06:19.787869217+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/config.(*FileLoader).Run","file":"/home/installadm/dev/github/sparrow/pkg/config/file.go","line":47},"msg":"Reading config from file","file":"./.tmp/run-config.yaml"}
{"time":"2024-01-24T15:06:19.787912805+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow/targets.(*gitlabTargetManager).Reconcile","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/targets/gitlab.go","line":80},"msg":"Starting global gitlabTargetManager reconciler"}
{"time":"2024-01-24T15:06:19.787884219+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/sparrow.(*Sparrow).api.func1","file":"/home/installadm/dev/github/sparrow/pkg/sparrow/api.go","line":81},"msg":"Serving Api","addr":":8080"}
{"time":"2024-01-24T15:06:19.78822861+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).Startup","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":117},"msg":"Initializing health check"}
{"time":"2024-01-24T15:06:19.788326925+01:00","level":"DEBUG","source":{"function":"github.com/caas-team/sparrow/pkg/checks/latency.(*Latency).Startup","file":"/home/installadm/dev/github/sparrow/pkg/checks/latency/latency.go","line":117},"msg":"Initializing latency check"}
{"time":"2024-01-24T15:06:19.788363549+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/checks/latency.(*Latency).Run","file":"/home/installadm/dev/github/sparrow/pkg/checks/latency/latency.go","line":91},"msg":"Starting latency check","interval":"20s"}
{"time":"2024-01-24T15:06:19.788369506+01:00","level":"INFO","source":{"function":"github.com/caas-team/sparrow/pkg/checks/health.(*Health).Run","file":"/home/installadm/dev/github/sparrow/pkg/checks/health/health.go","line":89},"msg":"Starting healthcheck","interval":"20s"}

TODO