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



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/simple/sql/logging.rb', line 6

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 => 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