Class: Sequel::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/sequel/database.rb

Instance Method Summary collapse

Instance Method Details

#log_connection_yield(sql, conn, args = nil) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sequel/database.rb', line 7

def log_connection_yield sql, conn, args = nil
  log_connection_info = (connection_info conn if conn && log_connection_info)
  log_args = ("; #{args.inspect}" if args)
  sql_for_log = "#{log_connection_info}#{sql}#{log_args}"
  start = Time.now
  begin
    ::ActiveSupport::Notifications.instrument(
      "sql.sequel",
      sql: sql,
      name: self.class,
      binds: args
    ) do
      yield
    end
  rescue StandardError => error
    log_exception error, sql_for_log unless @loggers.empty?
    raise
  ensure
    log_duration Time.now - start, sql_for_log unless error || @loggers.empty?
  end
end

#log_yield(sql, args = nil, &block) ⇒ Object



29
30
31
# File 'lib/sequel/database.rb', line 29

def log_yield sql, args = nil, &block
  log_connection_yield(sql, nil, args, &block)
end