Class: PerformanceLogger

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::DateHelper
Defined in:
lib/performance_logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(log_file: nil) ⇒ PerformanceLogger

Returns a new instance of PerformanceLogger.



4
5
6
7
# File 'lib/performance_logger.rb', line 4

def initialize(log_file:nil)
  raise 'Log file must be given' unless log_file.present?
  @log_file = log_file
end

Instance Method Details

#log(message) ⇒ Object



25
26
27
# File 'lib/performance_logger.rb', line 25

def log(message)
  logger.info(message)
end

#wrap {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/performance_logger.rb', line 9

def wrap
  log("----------------------------------")
  start_time = Time.current
  log("Start time: #{start_time}")

  yield(self)

  end_time = Time.current
  log("End time: #{end_time}")
  total = end_time - start_time
  readable_total = distance_of_time_in_words(total)
  log("Total: #{readable_total}")
  log("Total in sec: #{total}")
  log("----------------------------------")
end