【发布时间】:2014-02-06 06:27:47
【问题描述】:
Sinatra 新手;我正在运行一些 rspec 测试,但在日志中得到了一堆不需要的噪音。如何摆脱日志中的过多噪音?我仔细检查了环境是否设置为 :test,这意味着记录器级别应设置为 WARN 而不是 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
噪音:
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
【问题讨论】:
-
根据the second answer on this thread,
Logger::ERROR需要回复:to_int。您可以启动控制台并尝试一下吗?如果它没有响应 to_int,sinatra 将使用默认的日志记录设置。