Module: Katello::Logging

Defined in:
app/lib/katello/logging.rb

Defined Under Namespace

Classes: Timer

Class Method Summary collapse

Class Method Details

.join_parts(hash) ⇒ Object



19
20
21
22
# File 'app/lib/katello/logging.rb', line 19

def self.join_parts(hash)
  hash ||= {}
  hash.map { |k, v| "#{k}=#{v}" }.join(' ')
end

.time(message, data: {}, logger: Rails.logger, level: :info) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/lib/katello/logging.rb', line 3

def self.time(message, data: {}, logger: Rails.logger, level: :info)
  start = Time.now
  data[:success] = true

  begin
    yield(data)
  rescue => e
    data[:success] = false
    raise e
  ensure
    data[:duration] = ((Time.now - start) * 1000).truncate(2)
    data_string = join_parts(data)
    logger.send(level, "#{message} #{data_string}")
  end
end