Module: Sequel::ServerLogging

Defined in:
lib/sequel/extensions/server_logging.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(db) ⇒ Object

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



30
31
32
33
34
35
# 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

Instance Method Details

#connect(server) ⇒ Object

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



39
40
41
42
43
# 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) ⇒ Object

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



46
47
48
49
50
# File 'lib/sequel/extensions/server_logging.rb', line 46

def disconnect_connection(conn)
  super
ensure
  Sequel.synchronize{@server_connection_map.delete(conn)}
end