Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: logging verbosity #87

Merged
merged 7 commits into from
Jan 25, 2024
Merged

feat: logging verbosity #87

merged 7 commits into from
Jan 25, 2024

Conversation

lvlcn-t
Copy link
Collaborator

@lvlcn-t lvlcn-t commented Jan 24, 2024

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 5d8c823

For additional information look at the commits.

Tests done

I've added unit tests for the logger package:

  • Unit tests succeeded

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

  • I've assigned this PR to myself
  • I've labeled this PR correctly

@lvlcn-t lvlcn-t added the feature Introduces a new feature label Jan 24, 2024
@lvlcn-t lvlcn-t added this to the 0.4.0 milestone Jan 24, 2024
@lvlcn-t lvlcn-t self-assigned this Jan 24, 2024
@lvlcn-t lvlcn-t changed the title Feat/logging verbosity feat: logging verbosity Jan 24, 2024
Copy link
Collaborator

@puffitos puffitos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I've added a commit regarding some name shadowing in the tests.

@lvlcn-t lvlcn-t merged commit d41fb43 into main Jan 25, 2024
@lvlcn-t lvlcn-t deleted the feat/logging-verbosity branch January 25, 2024 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Introduces a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature: Dynamically switch logging verbosity
3 participants