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

Inject logger using context #1116

Merged
merged 1 commit into from
Nov 7, 2024
Merged

Inject logger using context #1116

merged 1 commit into from
Nov 7, 2024

Conversation

gandarez
Copy link
Member

@gandarez gandarez commented Nov 6, 2024

This PR replaces the static logger with a more flexible way injected in the context.

The reason for this is to make tests more concise without workarounds by removing skipped ones. It also make log enabled everywhere through the context by simply calling log.Extract(ctx). Although it changes lots of files, the main change is around the log package and the other files added context as parameter.

Tests that were skipped in Windows:

  • TestSendHeartbeats_RateLimited
  • TestRunCmd_BackoffNotLogged
  • TestRunCmd_BackoffLoggedWithVerbose
  • TestWithDetection_SshConfig_Hostname
  • TestWithDetection_SshConfig_UserKnownHostsFile_Mismatch
  • TestWithDetection_SshConfig_UserKnownHostsFile_Match
  • TestWithDetection_Filtered

Other tests fixed:

  • TestLoadHeartbeatParams_ExtraHeartbeats_NoData

In the future we can also inject the viper instance.

@gandarez gandarez self-assigned this Nov 6, 2024
@gandarez gandarez force-pushed the feature/inject-logger branch 8 times, most recently from a3cb116 to b4cadcc Compare November 6, 2024 21:37
@gandarez gandarez marked this pull request as ready for review November 7, 2024 00:15
@alanhamlett alanhamlett merged commit 7414c6e into develop Nov 7, 2024
39 checks passed
@alanhamlett alanhamlett deleted the feature/inject-logger branch November 7, 2024 12:35
Copy link

codecov bot commented Nov 7, 2024

Codecov Report

Attention: Patch coverage is 69.95025% with 302 lines in your changes missing coverage. Please review.

Project coverage is 63.10%. Comparing base (e9a9451) to head (17a73ef).
Report is 2 commits behind head on develop.

Files with missing lines Patch % Lines
cmd/run.go 43.15% 52 Missing and 2 partials ⚠️
pkg/log/log.go 44.26% 34 Missing ⚠️
cmd/heartbeat/heartbeat.go 60.00% 15 Missing and 3 partials ⚠️
pkg/remote/remote.go 75.00% 17 Missing ⚠️
pkg/log/context.go 0.00% 14 Missing ⚠️
pkg/offline/offline.go 80.95% 12 Missing ⚠️
pkg/regex/regex.go 52.38% 10 Missing ⚠️
pkg/api/api.go 10.00% 9 Missing ⚠️
pkg/heartbeat/format.go 52.63% 9 Missing ⚠️
pkg/api/transport.go 0.00% 8 Missing ⚠️
... and 51 more
@@             Coverage Diff             @@
##           develop    #1116      +/-   ##
===========================================
- Coverage    63.11%   63.10%   -0.02%     
===========================================
  Files          383      384       +1     
  Lines        16561    16851     +290     
===========================================
+ Hits         10452    10633     +181     
- Misses        5540     5647     +107     
- Partials       569      571       +2     
Flag Coverage Δ
unittests 63.10% <69.95%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cmd/logfile/logfile.go 83.33% <100.00%> (ø)
cmd/offlinecount/offlinecount.go 37.50% <100.00%> (ø)
cmd/offlineprint/offlineprint.go 53.33% <100.00%> (ø)
pkg/api/diagnostic.go 58.18% <100.00%> (+1.57%) ⬆️
pkg/api/fileexperts.go 76.56% <100.00%> (+0.75%) ⬆️
pkg/api/goal.go 73.33% <100.00%> (ø)
pkg/api/option.go 65.85% <100.00%> (+0.56%) ⬆️
pkg/api/statusbar.go 75.00% <100.00%> (ø)
pkg/apikey/apikey.go 100.00% <100.00%> (ø)
pkg/deps/unknown.go 81.25% <100.00%> (ø)
... and 65 more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants