Skip to content

Commit 48cf4b4

Browse files
committed
Always write debug.log during spec runs
Match the activerecord-oracle_enhanced-adapter convention of writing spec SQL to debug.log unconditionally. The previous PLSQL_DEBUG_LOG env var gate is removed so debug.log is always available when tests fail, and debug.log is added to .gitignore.
1 parent 5b75424 commit 48cf4b4

2 files changed

Lines changed: 24 additions & 25 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pkg
88
log
99
tmp
1010
sqlnet.log
11+
debug.log
1112
Gemfile.lock
1213
*.zip
1314
.idea

spec/support/sql_logger.rb

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
1-
# Enable with: PLSQL_DEBUG_LOG=debug.log bundle exec rspec
1+
# Always write SQL executed during the spec run to debug.log.
22
# Logger args mirror activerecord-oracle_enhanced-adapter's spec logger
33
# (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"
65

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+
}
1110

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
1716

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
2221

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
2725
end
26+
end
2827

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)
3130

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
3533
end

0 commit comments

Comments
 (0)