mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Disable colorize logging of SQL and reduce unnecessary invokation of sql_color matching
When the `colorize_logging` is disabled, logs do not colorize the SQL queries. But the `sql_color` method is always invoked which due to regex matching results in slow queries. This PR fixes #38685 and removes unnecessary invokation of `sql_color` method when `colorize_logging` is disabled
This commit is contained in:
parent
a3f4a62e2c
commit
85b5cd344b
2 changed files with 11 additions and 1 deletions
|
@ -44,7 +44,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
name = colorize_payload_name(name, payload[:name])
|
name = colorize_payload_name(name, payload[:name])
|
||||||
sql = color(sql, sql_color(sql), true)
|
sql = color(sql, sql_color(sql), true) if colorize_logging
|
||||||
|
|
||||||
debug " #{name} #{sql}#{binds}"
|
debug " #{name} #{sql}#{binds}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -96,6 +96,16 @@ class LogSubscriberTest < ActiveRecord::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_logging_sql_coloration_disabled
|
||||||
|
logger = TestDebugLogSubscriber.new
|
||||||
|
logger.colorize_logging = false
|
||||||
|
|
||||||
|
SQL_COLORINGS.each do |verb, color_regex|
|
||||||
|
logger.sql(Event.new(0.9, sql: verb.to_s))
|
||||||
|
assert_no_match(/#{REGEXP_BOLD}#{color_regex}#{verb}#{REGEXP_CLEAR}/i, logger.debugs.last)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_basic_payload_name_logging_coloration_generic_sql
|
def test_basic_payload_name_logging_coloration_generic_sql
|
||||||
logger = TestDebugLogSubscriber.new
|
logger = TestDebugLogSubscriber.new
|
||||||
logger.colorize_logging = true
|
logger.colorize_logging = true
|
||||||
|
|
Loading…
Reference in a new issue