How to show general_query log with Sequel gem in terminal

I have a web server that uses Sinatra and Sequel gem. I would like to know if it is possible to print every request executed in the console.

I found in the Sequel documentation that I can configure the path to the log file.

You can also specify additional parameters, such as connection pool size or loggers for logging SQL queries:

DB = Sequel.connect("postgres://user:password@host:port/database_name",  
:max_connections => 10, :logger => Logger.new('log/db.log'))

However, I could not find anything about how to print requests in the console, and not in the log.

+3
source share
1 answer

You can, and you can also register with several registrars, see example below

db_location_test = "/db/reservation.accdb"
log_file_path = "#{__FILE__}_#{Time.now.strftime("%Y%m%d")}.txt"
log_file = File.open(log_file_path, "a")
$filelog = Logger.new log_file
$console = Logger.new STDOUT

$console.info "connecting to access database" #only logged to console
sConnectionStringAccess = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=#{db_location_test}"
#sql will be logged to both file and console
DBA = Sequel.ado(:conn_string=>sConnectionStringAccess, :loggers=>[$filelog,$console])

class Reservations < Sequel::Model(:TABLE_RESERVATIONS);end

Reservations.all.each do |record|
  $console.info Hash[record]
end
+2
source

All Articles