aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/log_subscriber.rb
diff options
context:
space:
mode:
authorPeter Boling <peter.boling@gmail.com>2015-07-17 13:23:59 -0700
committerPeter Boling <peter.boling@gmail.com>2015-07-17 13:23:59 -0700
commitbec65fa261b9803c19edbbe9dc89836e1edf78c7 (patch)
tree62c238adfce951a29af7c9fd0be30d72db3d5e64 /activerecord/lib/active_record/log_subscriber.rb
parent2c79122c0bbd61dcef12b95c80e025490d5a9783 (diff)
downloadrails-bec65fa261b9803c19edbbe9dc89836e1edf78c7.tar.gz
rails-bec65fa261b9803c19edbbe9dc89836e1edf78c7.tar.bz2
rails-bec65fa261b9803c19edbbe9dc89836e1edf78c7.zip
Improve sql logging coloration in `ActiveRecord::LogSubscriber`.
- Improves coloring for statements like: # Become WHITE SELECT * FROM ( SELECT * FROM mytable FOR UPDATE ) ss WHERE col1 = 5; LOCK TABLE table_name IN ACCESS EXCLUSIVE MODE; # Becomes RED ROLLBACK - Reinstates the coloration of the `payload[:name]`. Instead of simple alternating colors, adds meaning: - `MAGENTA` for `"SQL"` or `blank?` payload names - `CYAN` for Model Load/Exists - Introduces specs for sql coloration. - Introduces specs for payload name coloration. GH#20885
Diffstat (limited to 'activerecord/lib/active_record/log_subscriber.rb')
-rw-r--r--activerecord/lib/active_record/log_subscriber.rb28
1 files changed, 21 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/log_subscriber.rb b/activerecord/lib/active_record/log_subscriber.rb
index 4d597a0ab1..9e3f1bfb9e 100644
--- a/activerecord/lib/active_record/log_subscriber.rb
+++ b/activerecord/lib/active_record/log_subscriber.rb
@@ -47,7 +47,11 @@ module ActiveRecord
binds = " " + payload[:binds].map { |attr| render_bind(attr) }.inspect
end
- name = color(name, nil, true)
+ if payload[:name].blank? || payload[:name] == "SQL" # SQL vs Model Load/Exists
+ name = color(name, MAGENTA, true)
+ else
+ name = color(name, CYAN, true)
+ end
sql = color(sql, sql_color(sql), true)
debug " #{name} #{sql}#{binds}"
@@ -55,12 +59,22 @@ module ActiveRecord
def sql_color(sql)
case sql
- when /\s*\Ainsert/i then GREEN
- when /\s*\Aselect/i then BLUE
- when /\s*\Aupdate/i then YELLOW
- when /\s*\Adelete/i then RED
- when /transaction\s*\Z/i then CYAN
- else MAGENTA
+ when /\A\s*rollback/mi then
+ RED
+ when /\s*.*?select .*for update/mi, /\A\s*lock/mi then
+ WHITE
+ when /\A\s*select/i then
+ BLUE
+ when /\A\s*insert/i then
+ GREEN
+ when /\A\s*update/i then
+ YELLOW
+ when /\A\s*delete/i then
+ RED
+ when /transaction\s*\Z/i then
+ CYAN
+ else
+ MAGENTA
end
end