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
merged 1 commit into from Jul 25, 2019

Conversation

@jozefhajnala
Copy link
Contributor

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.

@codecov-io

This comment has been minimized.

Copy link

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.

@daroczig

This comment has been minimized.

Copy link
Owner

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()?

@jozefhajnala jozefhajnala force-pushed the jozefhajnala:master branch from 77afd3f to 40332ab Jul 24, 2019

@jozefhajnala

This comment has been minimized.

Copy link
Contributor Author

commented Jul 24, 2019

Sure, would something like this be better?

R/logger.R Show resolved Hide resolved
@daroczig
Copy link
Owner

left a comment

thanks!

@daroczig daroczig merged commit 69f4c1f into daroczig:master Jul 25, 2019

3 checks passed

codecov/patch 100% of diff hit (target 78.71%)
Details
codecov/project Absolute coverage decreased by -0.1% but relative coverage increased by +21.28% compared to f9bff45
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.