Module: PgDice::LogHelper

Included in:
ConfigurationFileLoader, DatabaseConnection, PgSliceManager, PgSliceManagerFactory
Defined in:
lib/pgdice/log_helper.rb

Overview

LogHelper provides a convenient wrapper block to log out the duration of an operation

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.log_duration(message, logger, options = {}) ⇒ Object

If you want to pass the the result of your block into the message you can use ‘{}’ and it will be substituted with the result of your block.



18
19
20
21
22
23
24
25
26
27
# File 'lib/pgdice/log_helper.rb', line 18

def log_duration(message, logger, options = {})
  logger.error { 'log_duration called without a block. Cannot time the duration of nothing.' } unless block_given?
  time_start = Time.now.utc
  result = yield
  time_end = Time.now.utc

  formatted_message = format_message(time_end, time_start, message, result)
  logger.public_send(options[:log_level] || :debug) { formatted_message }
  result
end

Instance Method Details

#blank?(string) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/pgdice/log_helper.rb', line 6

def blank?(string)
  string.nil? || string.empty?
end

#squish(string) ⇒ Object



10
11
12
13
# File 'lib/pgdice/log_helper.rb', line 10

def squish(string)
  string ||= ''
  string.gsub(/\s+/, ' ')
end