/usr/lib/ruby/vendor_ruby/sequel/database/logging.rb is in ruby-sequel 3.33.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | module Sequel
class Database
# ---------------------
# :section: 6 - Methods relating to logging
# This methods affect relating to the logging of executed SQL.
# ---------------------
# Numeric specifying the duration beyond which queries are logged at warn
# level instead of info level.
attr_accessor :log_warn_duration
# Array of SQL loggers to use for this database.
attr_accessor :loggers
# Log level at which to log SQL queries. This is actually the method
# sent to the logger, so it should be the method name symbol. The default
# is :info, it can be set to :debug to log at DEBUG level.
attr_accessor :sql_log_level
# Log a message at level info to all loggers.
def log_info(message, args=nil)
log_each(:info, args ? "#{message}; #{args.inspect}" : message)
end
# Yield to the block, logging any errors at error level to all loggers,
# and all other queries with the duration at warn or info level.
def log_yield(sql, args=nil)
return yield if @loggers.empty?
sql = "#{sql}; #{args.inspect}" if args
start = Time.now
begin
yield
rescue => e
log_each(:error, "#{e.class}: #{e.message.strip}: #{sql}")
raise
ensure
log_duration(Time.now - start, sql) unless e
end
end
# Remove any existing loggers and just use the given logger:
#
# DB.logger = Logger.new($stdout)
def logger=(logger)
@loggers = Array(logger)
end
private
# Log the given SQL and then execute it on the connection, used by
# the transaction code.
def log_connection_execute(conn, sql)
log_yield(sql){conn.send(connection_execute_method, sql)}
end
# Log message with message prefixed by duration at info level, or
# warn level if duration is greater than log_warn_duration.
def log_duration(duration, message)
log_each((lwd = log_warn_duration and duration >= lwd) ? :warn : sql_log_level, "(#{sprintf('%0.6fs', duration)}) #{message}")
end
# Log message at level (which should be :error, :warn, or :info)
# to all loggers.
def log_each(level, message)
@loggers.each{|logger| logger.send(level, message)}
end
end
end
|