1

Is there a way to silence/disable mysql output in the development.log?

For example this stuff:

SQL (0.4ms)  INSERT INTO `billing_infos` (`billing_method`, `city`, `company_id`, `country`, `created_at`, `email`, `fax_number`, `phone_number`, `postal_code`, `province`, `street`, `updated_at`) VALUES (NULL, 'Montreal', NULL, 'Canada', '2011-10-26 20:53:45', NULL, NULL, '(123) 456 7890', 'H1H1H1', 'QC', '1111 Temp', '2011-10-26 20:53:45')
 (0.3ms)  COMMIT
 (0.2ms)  BEGIN
 (0.1ms)  COMMIT
 (0.1ms)  BEGIN
 (0.4ms)  SELECT 1 FROM `sectors` WHERE (`sectors`.`name` = BINARY 'General 25' AND `sectors`.`id` != 1) LIMIT 1

2 Answers 2

4

If you want to suppress almost all log output, @Shirjeel's approach will work, though I find it a bit heavy handed.

If you prefer to suppress output for a single ActiveRecord class, and only within a specific block, you can use silence:

BillingInfo.silence do
  BillingInfo.create(:city => "Montreal")
  BillingInfo.create(:city => "Ottawa")
  ... etc
end

If you want to suppress output for all ActiveRecord subclasses, you can do

ActiveRecord::Base.silence do
  ... manipulate database quietly here...
end

I use this when I'm importing a large block of records or generating large test cases.

1
  • Turns out this is deprecated in Rails 4.0 due to thread safety issues. There's no alternative that I know of.
    – aNoble
    Aug 30, 2013 at 23:36
1

Add following line to your config/environments/development.rb file

config.log_level = :info

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.