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

Evaluate arguments only if they are to be logged #27

merged 1 commit into from Jul 25, 2019


Copy link

@jozefhajnala jozefhajnala commented Jul 23, 2019

This PR proposes that arguments passed as ... are only evaluated if they are to be logged.

Motivation and background

This increases performance if logs on certain levels (e.g. TRACE) require non-negligible time to produce. One practical example is logging the hashes of files being read for reconciliation purposes. Currently, if we use:

logger::log_trace("md5=", tools::md5sum(filePath))

the md5sum will be calculated regardless of the threshold, increasing runtime even if the threshold is lower than that for TRACE and nothing will be logged.

After the change, the arguments would be evaluated only if they really are to be logged and therefore are needed.

Copy link

@codecov-io codecov-io commented Jul 23, 2019

Codecov Report

Merging #27 into master will decrease coverage by 0.1%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #27      +/-   ##
- Coverage   78.71%   78.61%   -0.11%     
  Files          11       11              
  Lines         357      360       +3     
+ Hits          281      283       +2     
- Misses         76       77       +1
Impacted Files Coverage Δ
R/logger.R 96.11% <100%> (-0.89%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f9bff45...40332ab. Read the comment docs.


Copy link

@daroczig daroczig commented Jul 23, 2019

That's a good point, thanks!

But wouldn't it be easier to compare defintion$threshold with level early on even before defining log_arg and issue a next()?


Copy link
Contributor Author

@jozefhajnala jozefhajnala commented Jul 24, 2019

Sure, would something like this be better?


R/logger.R Show resolved Hide resolved
Copy link

@daroczig daroczig left a comment



@daroczig daroczig merged commit 69f4c1f into daroczig:master Jul 25, 2019
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants