Skip to content

Commit

Permalink
Added ActiveRecord::Base.colorize_logging to control whether to use c…
Browse files Browse the repository at this point in the history
…olors in logs or not (on by default)

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@860 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Mar 6, 2005
1 parent 7ba3903 commit 911614d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN* *SVN*


* Added ActiveRecord::Base.colorize_logging to control whether to use colors in logs or not (on by default)

* Added support for timestamp with time zone in PostgreSQL #560 [Scott Barron] * Added support for timestamp with time zone in PostgreSQL #560 [Scott Barron]


* Added MultiparameterAssignmentErrors and AttributeAssignmentError exceptions #777 [demetrius]. Documentation: * Added MultiparameterAssignmentErrors and AttributeAssignmentError exceptions #777 [demetrius]. Documentation:
Expand Down
6 changes: 6 additions & 0 deletions activerecord/lib/active_record/base.rb
Expand Up @@ -264,6 +264,12 @@ def self.inherited(child) #:nodoc:
cattr_accessor :pluralize_table_names cattr_accessor :pluralize_table_names
@@pluralize_table_names = true @@pluralize_table_names = true


# Determines whether or not to use ANSI codes to colorize the logging statements committed by the connection adapter. These colors
# makes it much easier to overview things during debugging (when used through a reader like +tail+ and on a black background), but
# may complicate matters if you use software like syslog. This is true, by default.
cattr_accessor :colorize_logging
@@colorize_logging = true

# Determines whether to use Time.local (using :local) or Time.utc (using :utc) when pulling dates and times from the database. # Determines whether to use Time.local (using :local) or Time.utc (using :utc) when pulling dates and times from the database.
# This is set to :local by default. # This is set to :local by default.
cattr_accessor :default_timezone cattr_accessor :default_timezone
Expand Down
Expand Up @@ -422,16 +422,20 @@ def log_info(sql, name, runtime)
end end


def format_log_entry(message, dump = nil) def format_log_entry(message, dump = nil)
if @@row_even then if ActiveRecord::Base.colorize_logging
@@row_even = false; caller_color = "1;32"; message_color = "4;33"; dump_color = "1;37" if @@row_even then
@@row_even = false; caller_color = "1;32"; message_color = "4;33"; dump_color = "1;37"
else
@@row_even = true; caller_color = "1;36"; message_color = "4;35"; dump_color = "0;37"
end

log_entry = " \e[#{message_color}m#{message}\e[m"
log_entry << " \e[#{dump_color}m%s\e[m" % dump if dump.kind_of?(String) && !dump.nil?
log_entry << " \e[#{dump_color}m%p\e[m" % dump if !dump.kind_of?(String) && !dump.nil?
log_entry
else else
@@row_even = true; caller_color = "1;36"; message_color = "4;35"; dump_color = "0;37" "%s %s" % [message, dump]
end end

log_entry = " \e[#{message_color}m#{message}\e[m"
log_entry << " \e[#{dump_color}m%s\e[m" % dump if dump.kind_of?(String) && !dump.nil?
log_entry << " \e[#{dump_color}m%p\e[m" % dump if !dump.kind_of?(String) && !dump.nil?
log_entry
end end
end end


Expand Down

0 comments on commit 911614d

Please sign in to comment.