Merge branch '8784-dir-listings'
[arvados.git] / services / api / lib / log_reuse_info.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 module LogReuseInfo
6   # log_reuse_info logs whatever the given block returns, if
7   # log_reuse_decisions is enabled. It accepts a block instead of a
8   # string because in some cases constructing the strings involves
9   # doing expensive things like database queries, and we want to skip
10   # those when logging is disabled.
11   def log_reuse_info(candidates=nil)
12     if Rails.configuration.log_reuse_decisions
13       msg = yield
14       if !candidates.nil?
15         msg = "have #{candidates.count} candidates " + msg
16       end
17       Rails.logger.info("find_reusable: " + msg)
18     end
19   end
20 end