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.

Sign up to request clarification or add additional context in comments.

1 Comment

Turns out this is deprecated in Rails 4.0 due to thread safety issues. There's no alternative that I know of.
1

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

config.log_level = :info

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.