Module: Simple::SQL::Logging

Extended by:
Logging
Included in:
Logging
Defined in:
lib/simple/sql/logging.rb

Instance Method Summary collapse

Instance Method Details

#yield_logged(sql, *args, &_block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/simple/sql/logging.rb', line 9

def yield_logged(sql, *args, &_block)
  r0 = Time.now
  rv = yield
  realtime = Time.now - r0
  ::Simple::SQL.logger.debug "[sql] %.3f secs: %s" % [realtime, format_query(sql, *args)]
  rv
rescue StandardError => e
  realtime = Time.now - r0
  ::Simple::SQL.logger.warn "[sql] %.3f secs: %s:\n\tfailed with error %s" % [realtime, format_query(sql, *args), e.message]
  raise
end