caller_logging.rb

lib/sequel/extensions/caller_logging.rb
Last Update: 2024-05-20 14:13:34 -0700

The caller_logging extension includes caller information before query logging, showing which code caused the query. It skips internal Sequel code, showing the first non-Sequel caller line.

DB.extension :caller_logging
DB[:table].first
# Logger:
# (0.000041s) (source: /path/to/app/foo/t.rb:12 in `get_first`) SELECT * FROM table LIMIT 1

You can further filter the caller lines by setting Database#caller_logging_ignore to a regexp of additional caller lines to ignore. This is useful if you have specific methods or internal extensions/plugins that you would also like to ignore as they obscure the code actually making the request.

DB.caller_logging_ignore = %r{/path/to/app/lib/plugins}

You can also format the caller before it is placed in the logger, using caller_logging_formatter:

DB.caller_logging_formatter = lambda do |caller|
  "(#{caller.sub(/\A\/path\/to\/app\//, '')})"
end
DB[:table].first
# Logger:
# (0.000041s) (foo/t.rb:12 in `get_first`) SELECT * FROM table LIMIT 1

Related module: Sequel::CallerLogging

Required files

  1. rbconfig