How do I tell ActiveRecord not to log any control chars

前端 未结 3 1498
死守一世寂寞
死守一世寂寞 2021-02-06 09:35

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         


        
3条回答
  •  梦如初夏
    2021-02-06 10:22

    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
    

提交回复
热议问题