Skip to content

Commit 261a8e1

Browse files
committed
Merge pull request rails#20607 from cmtonkinson/update-console-colors
More granular console SQL coloration
2 parents 9f94f73 + f5d8dd6 commit 261a8e1

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

activerecord/lib/active_record/log_subscriber.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,21 @@ def sql(event)
4747
binds = " " + payload[:binds].map { |attr| render_bind(attr) }.inspect
4848
end
4949

50-
if odd?
51-
name = color(name, CYAN, true)
52-
sql = color(sql, nil, true)
53-
else
54-
name = color(name, MAGENTA, true)
55-
end
50+
name = color(name, nil, true)
51+
sql = color(sql, sql_color(sql), true)
5652

5753
debug " #{name} #{sql}#{binds}"
5854
end
5955

60-
def odd?
61-
@odd = !@odd
56+
def sql_color(sql)
57+
case sql
58+
when /\s*\Ainsert/i then GREEN
59+
when /\s*\Aselect/i then BLUE
60+
when /\s*\Aupdate/i then YELLOW
61+
when /\s*\Adelete/i then RED
62+
when /transaction\s*\Z/i then CYAN
63+
else MAGENTA
64+
end
6265
end
6366

6467
def logger

0 commit comments

Comments
 (0)