From f7c7de4e88d481e4d571f5ee6dc8f206d4e96fb1 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Wed, 13 Nov 2024 15:09:57 +0100 Subject: [PATCH] Pass the provided Savon/custom logger to Faraday If the Savon logger isn't passed to Faraday, it builds a new logger to $stdout and logs to it. This results in stdout logging whenever `log: true` is set as a savon option, instead of logging to a file or so. Passing the Savon/custom logger to Faraday avoids the creation of a second logger object by Faraday and allows to capture all logs to a user provided Logger object. This patch also removes the `level` option, which is no recognized Faraday option. There is the option `log_level` only, which determines which log level which the messages are flagged by Faraday. In contrast the `log_level` option of Savon determines the minimum level of logs, which are captured by the logger. --- lib/savon/request.rb | 2 +- spec/savon/options_spec.rb | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/savon/request.rb b/lib/savon/request.rb index 5197019e..7f330bf3 100644 --- a/lib/savon/request.rb +++ b/lib/savon/request.rb @@ -77,7 +77,7 @@ def configure_adapter end def configure_logging - connection.response(:logger, nil, headers: @globals[:log_headers], level: @globals[:logger].level) if @globals[:log] + connection.response(:logger, @globals[:logger], headers: @globals[:log_headers]) if @globals[:log] end protected diff --git a/spec/savon/options_spec.rb b/spec/savon/options_spec.rb index 5049b1a6..41db9c31 100644 --- a/spec/savon/options_spec.rb +++ b/spec/savon/options_spec.rb @@ -331,7 +331,7 @@ def to_s end it "silences Faraday as well" do - Faraday::Connection.any_instance.expects(:response).with(:logger, nil, {:headers => true, :level => 0}).never + Faraday::Connection.any_instance.expects(:response).never new_client(:log => false) end @@ -346,7 +346,7 @@ def to_s end it "turns Faraday logging back on as well" do - Faraday::Connection.any_instance.expects(:response).with(:logger, nil, {:headers => true, :level => 0}).at_least_once + Faraday::Connection.any_instance.expects(:response).with(:logger, kind_of(Logger), {:headers => true}).at_least_once new_client(:log => true) end end @@ -367,10 +367,10 @@ def to_s end it "sets the logger of faraday connection as well" do - Faraday::Connection.any_instance.expects(:response).with(:logger, nil, {:headers => true, :level => 0}).at_least_once + custom_logger = Logger.new($stdout) + custom_logger.level = :fatal + Faraday::Connection.any_instance.expects(:response).with(:logger, custom_logger, {:headers => true}).at_least_once mock_stdout { - custom_logger = Logger.new($stdout) - client = new_client(:endpoint => @server.url, :logger => custom_logger, :log => true) client.call(:authenticate) }