forked from rsim/ruby-plsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_logger.rb
More file actions
33 lines (27 loc) · 1.04 KB
/
Copy pathsql_logger.rb
File metadata and controls
33 lines (27 loc) · 1.04 KB
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
# Always write SQL executed during the spec run to debug.log.
# Logger args mirror activerecord-oracle_enhanced-adapter's spec logger
# (shift_age, shift_size) so debug.log behaves the same way.
require "logger"
PLSQL_DEBUG_LOGGER = Logger.new("debug.log", 0, 100 * 1024 * 1024)
PLSQL_DEBUG_LOGGER.formatter = ->(_sev, time, _prog, msg) {
"#{time.iso8601(6)} #{msg}\n"
}
module PLSQLSQLLogger
def exec(sql, *bindvars)
PLSQL_DEBUG_LOGGER.info("EXEC #{sql.strip}#{bindvars.empty? ? '' : " BINDS=#{bindvars.inspect}"}")
super
end
def cursor_from_query(sql, bindvars = [], options = {})
PLSQL_DEBUG_LOGGER.info("QUERY #{sql.strip}#{bindvars.empty? ? '' : " BINDS=#{bindvars.inspect}"}")
super
end
def parse(sql)
PLSQL_DEBUG_LOGGER.info("PARSE #{sql.strip}")
super
end
end
PLSQL::OCIConnection.prepend(PLSQLSQLLogger) if defined?(PLSQL::OCIConnection)
PLSQL::JDBCConnection.prepend(PLSQLSQLLogger) if defined?(PLSQL::JDBCConnection)
if defined?(ActiveRecord::Base)
ActiveRecord::Base.logger = PLSQL_DEBUG_LOGGER
end