Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable colorize logging of SQL and reduce unnecessary invocation of sql_color matching #38690

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/log_subscriber.rb
Expand Up @@ -44,7 +44,7 @@ def sql(event)
end

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}"
end
Expand Down
10 changes: 10 additions & 0 deletions activerecord/test/cases/log_subscriber_test.rb
Expand Up @@ -96,6 +96,16 @@ def test_basic_query_logging_coloration
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
logger = TestDebugLogSubscriber.new
logger.colorize_logging = true
Expand Down