How to tell ActiveRecord not to register control characters

Is it possible to specify an active record so as not to register ansi color codes when recording it?

Eg. I do not want this in my magazines.

[4;36;1mSQL (0.1ms)[0m [0;1mSELECT count(*) AS count_all FROM `users` WHERE (`user`.id = 133) [0m 

Instead, I want:

 SQL (0.1ms) SELECT count(*) AS count_all FROM `users` WHERE (`user`.id = 133) 

I'm not looking for a solution that involves cleaning up the mess after the fact.

+6
ruby-on-rails activerecord
source share
3 answers

Answer for Rails 3:

 config.colorize_logging = false 

See http://guides.rubyonrails.org/3_0_release_notes.html

ActiveRecord :: Base.colorize_logging and config.active_record.colorize_logging are deprecated in favor of Rails :: LogSubscriber.colorize_logging or config.colorize_logging

+9
source share

Add this to the appropriate environment file (in my case development.rb)

 config.active_record.colorize_logging = false 
+8
source share

I use this method in my jRuby scripts. The part that disables the coloring,

 ActiveSupport::LogSubscriber.colorize_logging = false 

get_jar_path is another method that returns the correct path if the script is in a JAR

 def activate_logger scriptname # delete logs after a month $log = Logger.new( "#{get_jar_path}/logs/#{scriptname}_#{Time.now.strftime("%Y%m%d")}.txt", 'monthly' ) # $log = Logger.new($stdout) ActiveRecord::Base.logger = $log ActiveRecord::Base.logger.level = Logger.const_get($debuglevel) ActiveSupport::LogSubscriber.colorize_logging = false $errors, $verwerkt = 0, 0 $log.info "start #{__FILE__}" end 
+4
source share

All Articles