Skip to content

Instantly share code, notes, and snippets.

@bryanstearns
Created March 11, 2011 01:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanstearns/865286 to your computer and use it in GitHub Desktop.
Save bryanstearns/865286 to your computer and use it in GitHub Desktop.
# Monkeypatch the activerecord logger to colorize database-changing statements different
# from non-changing statements (instead of the blue-baring it does by default)
class ActiveRecord::ConnectionAdapters::AbstractAdapter
protected
def format_log_entry(message, dump = nil)
if ActiveRecord::Base.colorize_logging
if message =~ / (Update|Create) /
message_color, dump_color = "4;35;1", "0"
else
message_color, dump_color = "4;36;1", "0;1"
end
log_entry = " \e[#{message_color}m#{message}\e[0m "
log_entry << "\e[#{dump_color}m%#{String === dump ? 's' : 'p'}\e[0m" % dump if dump
log_entry
else
"%s %s" % [message, dump]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment