Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell ActiveRecord not to log any control chars

Is there any way to tell active record not to log the ansi color codes when its logging stuff?

Eg. I do not want this in my logs.

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

Instead I want this:

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

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

like image 887
Sam Saffron Avatar asked Aug 17 '09 03:08

Sam Saffron


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

like image 162
bjelli Avatar answered Nov 05 '22 15:11

bjelli


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

config.active_record.colorize_logging = false 
like image 8
Sam Saffron Avatar answered Nov 05 '22 14:11

Sam Saffron


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

ActiveSupport::LogSubscriber.colorize_logging = false

get_jar_path is another method that returns the correct path in case 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
like image 5
peter Avatar answered Nov 05 '22 13:11

peter