module Sequel::ServerLogging

Public Class Methods

extended(db) click to toggle source

Initialize the hash mapping connections to shards, and turn on logging of connection info unless it has specifically been turned off.

# File lib/sequel/extensions/server_logging.rb, line 30
def self.extended(db)
  db.instance_exec do
    @server_connection_map ||= {}
    self.log_connection_info = true if log_connection_info.nil?
  end
end

Public Instance Methods

connect(server) click to toggle source

When setting up a new connection, associate the connection with the shard.

Calls superclass method
# File lib/sequel/extensions/server_logging.rb, line 39
def connect(server)
  conn = super
  Sequel.synchronize{@server_connection_map[conn] = server}
  conn
end
disconnect_connection(conn) click to toggle source

When disconnecting a connection, remove the related connection from the mapping.

Calls superclass method
# File lib/sequel/extensions/server_logging.rb, line 46
def disconnect_connection(conn)
  super
ensure
  Sequel.synchronize{@server_connection_map.delete(conn)}
end

Private Instance Methods

connection_info(conn) click to toggle source

Include the server with the connection's id.

# File lib/sequel/extensions/server_logging.rb, line 55
def connection_info(conn)
  "(conn: #{conn.__id__}, server: #{Sequel.synchronize{@server_connection_map[conn]}}) "
end