|
1 | | -# Enable with: PLSQL_DEBUG_LOG=debug.log bundle exec rspec |
| 1 | +# Always write SQL executed during the spec run to debug.log. |
2 | 2 | # Logger args mirror activerecord-oracle_enhanced-adapter's spec logger |
3 | 3 | # (shift_age, shift_size) so debug.log behaves the same way. |
4 | | -if (log_path = ENV["PLSQL_DEBUG_LOG"]) && !log_path.empty? |
5 | | - require "logger" |
| 4 | +require "logger" |
6 | 5 |
|
7 | | - PLSQL_DEBUG_LOGGER = Logger.new(log_path, 0, 100 * 1024 * 1024) |
8 | | - PLSQL_DEBUG_LOGGER.formatter = ->(_sev, time, _prog, msg) { |
9 | | - "#{time.iso8601(6)} #{msg}\n" |
10 | | - } |
| 6 | +PLSQL_DEBUG_LOGGER = Logger.new("debug.log", 0, 100 * 1024 * 1024) |
| 7 | +PLSQL_DEBUG_LOGGER.formatter = ->(_sev, time, _prog, msg) { |
| 8 | + "#{time.iso8601(6)} #{msg}\n" |
| 9 | +} |
11 | 10 |
|
12 | | - module PLSQLSQLLogger |
13 | | - def exec(sql, *bindvars) |
14 | | - PLSQL_DEBUG_LOGGER.info("EXEC #{sql.strip}#{bindvars.empty? ? '' : " BINDS=#{bindvars.inspect}"}") |
15 | | - super |
16 | | - end |
| 11 | +module PLSQLSQLLogger |
| 12 | + def exec(sql, *bindvars) |
| 13 | + PLSQL_DEBUG_LOGGER.info("EXEC #{sql.strip}#{bindvars.empty? ? '' : " BINDS=#{bindvars.inspect}"}") |
| 14 | + super |
| 15 | + end |
17 | 16 |
|
18 | | - def cursor_from_query(sql, bindvars = [], options = {}) |
19 | | - PLSQL_DEBUG_LOGGER.info("QUERY #{sql.strip}#{bindvars.empty? ? '' : " BINDS=#{bindvars.inspect}"}") |
20 | | - super |
21 | | - end |
| 17 | + def cursor_from_query(sql, bindvars = [], options = {}) |
| 18 | + PLSQL_DEBUG_LOGGER.info("QUERY #{sql.strip}#{bindvars.empty? ? '' : " BINDS=#{bindvars.inspect}"}") |
| 19 | + super |
| 20 | + end |
22 | 21 |
|
23 | | - def parse(sql) |
24 | | - PLSQL_DEBUG_LOGGER.info("PARSE #{sql.strip}") |
25 | | - super |
26 | | - end |
| 22 | + def parse(sql) |
| 23 | + PLSQL_DEBUG_LOGGER.info("PARSE #{sql.strip}") |
| 24 | + super |
27 | 25 | end |
| 26 | +end |
28 | 27 |
|
29 | | - PLSQL::OCIConnection.prepend(PLSQLSQLLogger) if defined?(PLSQL::OCIConnection) |
30 | | - PLSQL::JDBCConnection.prepend(PLSQLSQLLogger) if defined?(PLSQL::JDBCConnection) |
| 28 | +PLSQL::OCIConnection.prepend(PLSQLSQLLogger) if defined?(PLSQL::OCIConnection) |
| 29 | +PLSQL::JDBCConnection.prepend(PLSQLSQLLogger) if defined?(PLSQL::JDBCConnection) |
31 | 30 |
|
32 | | - if defined?(ActiveRecord::Base) |
33 | | - ActiveRecord::Base.logger = PLSQL_DEBUG_LOGGER |
34 | | - end |
| 31 | +if defined?(ActiveRecord::Base) |
| 32 | + ActiveRecord::Base.logger = PLSQL_DEBUG_LOGGER |
35 | 33 | end |
0 commit comments