server_logging.rb

Path: lib/sequel/extensions/server_logging.rb
Last Update: Sun Oct 02 21:06:53 +0000 2016

frozen-string-literal: true

The server_logging extension makes the logger include the server/shard the query was issued on. This makes it easier to use the logs when using sharding.

Example:

  DB.opts[:server]
  # {:read_only=>{}, :b=>{}}
  DB.extension :server_logging
  DB[:a].all
  # (0.000005s) (conn: 1014942550, server: read_only) SELECT * FROM a
  DB[:a].server(:b).all
  # (0.000004s) (conn: 997304100, server: b) SELECT * FROM a
  DB[:a].insert
  # (0.000004s) (conn: 1014374750, server: default) INSERT INTO a DEFAULT VALUES

In order for the server/shard to be correct for all connections, you need to use this before connections to the database are made, or you need to call Database#disconnect after loading this extension.

Related module: Sequel::ServerLogging

[Validate]