Skip to content

Commit

Permalink
Pass the provided Savon/custom logger to Faraday (#1017)
Browse files Browse the repository at this point in the history
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 not a 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.
  • Loading branch information
larskanis authored Nov 16, 2024
1 parent 2fd02fb commit 9cae923
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/savon/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions spec/savon/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit 9cae923

Please sign in to comment.