问题
While running a cucumber test I am getting (in addition to the test results) a lot of debug/log related output in the form:
D, [2013-03-06T12:21:38.911829 #49031] DEBUG -- : SOAP request:
D, [2013-03-06T12:21:38.911919 #49031] DEBUG -- : Pragma: no-cache, SOAPAction: "", Content-Type: text/xml;charset=UTF-8, Content-Length: 1592
W, [2013-03-06T12:21:38.912360 #49031] WARN -- : HTTPI executes HTTP POST using the httpclient adapter
D, [2013-03-06T12:21:39.410335 #49031] DEBUG -- : <?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
...
Is there a way to turn this output off? I have tried following the instructions in this post, and my config_spec.rb file is:
require "spec_helper"
describe Savon::Config do
let(:config) {
config = Savon::Config.new
config._logger = Savon::Logger.new
config.log_level = :error # changing the log level
HTTPI.log = false # to total silent the logging.
config
}
describe "#clone" do
it "clones the logger" do
logger = config.logger
clone = config.clone
logger.should_not equal(clone.logger)
end
end
it "allows to change the logger" do
logger = Logger.new("/dev/null")
config.logger = logger
config._logger.subject.should equal(logger)
end
it "allows to change the log level" do
Savon::Request.log_level = :info
config.log_level = :error
config._logger.level.should == :error
end
it "allows to enable/disable logging" do
config.log = false
config._logger.should be_a(Savon::NullLogger)
config.log = false
config._logger.should be_a(Savon::Logger)
end
end
But the logging still showing when I run the cucumber tests.
回答1:
By looking at the documentation for the Savon API you seem to be able to silence the logging by doing:
Savon.configure do |config|
config.log = false
end
The snippet above could be put in your Cucumber World or in features/support/env.rb
in order to silence the logging in Cucumber as well.
回答2:
Logs could be useful for debugging. So rather than silencing completely it might be better to put them in rails logs instead.
Here is how to do it in savon 2:
# config/initializers/savon.rb
HTTPI.logger = Rails.logger
# when initializing client
@client = Savon.client wsdl: '...', logger: Rails.logger
来源:https://stackoverflow.com/questions/15255224/cucumber-savon-omit-or-remove-logging-output