Pass block for logging.

This follows the good practice listed on http://guides.rubyonrails.org/debugging_rails_applications.html#impact-of-logs-on-performance.
Merge pull request #16440 from tgxworld/pass_log_in_block

Pass block for logging.