New to Sinatra; I'm running some rspec tests but getting a bunch of unwanted noise in the logs. How do I get rid of the excessive noise in the logs? I've double checked that the environment is set to :test, which means logger level should be set to WARN instead of DEBUG.
spec_helper:
require "./app"
require "sinatra"
require "rspec"
require "rack/test"
require "database_cleaner"
require "factory_girl"
set :environment, :test
FactoryGirl.definition_file_paths = %w{./factories ./test/factories ./spec/factories}
FactoryGirl.find_definitions
RSpec.configure do |config|
config.include Rack::Test::Methods
config.include FactoryGirl::Syntax::Methods
# Use color in STDOUT
config.color_enabled = true
# Use color not only in STDOUT but also in pagers and files
config.tty = true
# Use the specified formatter
config.formatter = :documentation # :progress, :html, :textmate
config.order = "random"
config.before(:suite) do
DatabaseCleaner.clean_with(:deletion)
end
config.before(:each) do
DatabaseCleaner.strategy = :deletion
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
def app
Sinatra::Application
end
app.rb
configure :test do
set :database, 'sqlite3:///test.sqlite'
set :logging, Logger::ERROR
end
noise:
D, [2014-01-16T22:14:28.481790 #75797] DEBUG -- : (0.6ms) commit transaction
D, [2014-01-16T22:14:28.484622 #75797] DEBUG -- : (0.1ms) begin transaction
With regards to Ben's answer: I put this in my spec helper:
ActiveRecord::Base.logger = nil unless ENV['LOG'] == true
There were some rare cases where I found that output useful, and including the conditional with environment variable made it super easy to turn logging on, while keeping it off by default.
It turns out that the noise is coming from the ActiveRecord logger.
Setting ActiveRecord::Base.logger = nil
in the spec helper gets rid of the SQL noise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With