Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pkg
log
tmp
sqlnet.log
debug.log
Gemfile.lock
*.zip
.idea
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ end
group :test, :development do
gem "rake", ">= 10.0"
gem "rspec", "~> 3.1"
gem "logger"

unless ENV["NO_ACTIVERECORD"]
gem "activerecord", github: "rails/rails", branch: "main"
Expand Down
33 changes: 33 additions & 0 deletions spec/support/sql_logger.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,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