2011-10-26 5 views
1

development.log에서 mysql 출력을 사용/사용하지 않도록 설정하는 방법이 있습니까? 예를 들어Rails 3.1에서 Silence ActiveRecord/MySQL 로그 출력?

이 물건 :

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 

답변

1

추가하여 설정/환경/development.rb 파일에 행 다음에

config.log_level = :info

4

당신이 Shirjeel의 @ 거의 모든 로그 출력을 억제하려면 접근 방식이 효과적 일지 모르지만 조금 무거워 보인다.

단일 액티브 클래스의 출력을 억제하는 것을 선호, 단지 특정 블록 내에서, 당신은 silence 사용할 수있는 경우 : 당신이 모든 액티브 서브 클래스의 출력을 억제하려면

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

을 수행 할 수 있습니다 do

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

큰 레코드 블록을 가져 오거나 큰 테스트 사례를 생성 할 때 이것을 사용합니다.

+0

스레드 안정성 문제로 인해 Rails 4.0에서는 더 이상 사용되지 않습니다. 내가 아는 대안은 없어. – aNoble

관련 문제