Skip to content

Evaluate arguments only if they are to be logged - #27

Merged
daroczig merged 1 commit into
daroczig:masterfrom
jozefhajnala:master
Jul 25, 2019
Merged

daroczig merged 1 commit into
daroczig:masterfrom
jozefhajnala:master

Conversation

@jozefhajnala

Copy link
Copy Markdown
Contributor

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

codecov-io commented Jul 23, 2019 •

Copy link
Copy Markdown

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

Copy link
Copy Markdown
Owner

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

Copy link
Copy Markdown
Contributor Author

Sure, would something like this be better?

Comment thread R/logger.R Resolved

@daroczig daroczig left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

thanks!

@daroczig
daroczig merged commit 69f4c1f into daroczig:master Jul 25, 2019
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.

3 participants