Logging with Rake

July 8, 2009

I’ve gotten a little tired of failing rake tasks that don’t give me enough diagnostic information with just the –trace option. Here’s a little snippet to redirect the ActiveRecord (and SQL in debug mode) output to stdout. Then pipe it into a file for safe keeping.

rake mytask LOG=DEBUG > mytask.out

def set_logger
  #configure ActiveRecord to log to Stdout
  if (log = (ENV['LOG']||ENV['log'])) && log.to_s.downcase != 'false'
    ActiveRecord::Base.logger = Logger.new(STDOUT)
    ActiveRecord::Base.logger.level = begin
      log =~ /^\d*$/ ? log.to_i : Logger.const_get(log.upcase)
    rescue
      Logger::INFO
    end
    puts "ActiveRecord to STDOUT level #{ActiveRecord::Base.logger.level}"
    ActiveRecord::Base.connection.instance_variable_set('@logger', ActiveRecord::Base.logger)
    Paperclip.options[:log] = true
  end
end

3 Responses to “Logging with Rake”


  1. Pillspot.org. Canadian Health&Care.Best quality drugs.No prescription online pharmacy.Special Internet Prices. Low price drugs. Order drugs online

    Buy:Viagra Super Active+.Cialis Soft Tabs.Soma.Viagra Professional.Propecia.Levitra.Cialis Super Active+.Tramadol.Viagra Super Force.Super Active ED Pack.Maxaman.Cialis.VPXL.Viagra.Cialis Professional.Viagra Soft Tabs.Zithromax….


  2. MedicamentSpot.com. Canadian Health&Care.Special Internet Prices.No prescription online pharmacy.Best quality drugs. High quality drugs. Buy drugs online

    Buy:Zyban.Lumigan.Nexium.Zovirax.Retin-A.Synthroid.Valtrex.Mega Hoodia.Arimidex.Human Growth Hormone.Actos.Accutane.Petcam (Metacam) Oral Suspension.Prevacid.100% Pure Okinawan Coral Calcium.Prednisolone….

  3. fog http://qdiamond6hujwg.AACEHARDWARE.INFO/tag/fog+lights+blue/ : blue…

    fog…

Leave a Reply