5

在运行黄瓜测试时,我得到了(除了测试结果之外)很多与调试/日志相关的输出,格式如下:

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" 
...

有没有办法关闭这个输出?我已经尝试按照这篇文章中的说明进行操作,我的 config_spec.rb 文件是:

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

但是当我运行黄瓜测试时,日志仍然显示。

4

2 回答 2

10

通过查看Savon API的文档,您似乎可以通过以下方式使日志记录静音:

Savon.configure do |config|
  config.log = false
 end

上面的代码片段可以放在你的Cucumber World中,或者features/support/env.rb为了让 Cucumber 中的日志保持静音。

于 2013-03-13T12:33:38.443 回答
1

日志可能对调试有用。因此,与其完全静音,不如将它们放在 Rails 日志中。

以下是在 savon 2 中的操作方法:

# config/initializers/savon.rb
HTTPI.logger = Rails.logger

# when initializing client
@client = Savon.client wsdl: '...', logger: Rails.logger
于 2014-02-19T10:43:36.280 回答