Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ $ bundle exec rake modelgen:latest
* **http_headers** sets custom HTTP headers. It must be a Hash of string to string.
* **http_proxy** sets host:port of a HTTP proxy server.
* **http_debug** enables debug message to STDOUT for each HTTP requests.
* **http_debug_logger** sets a custom `Logger` instance for HTTP debug logs. Requires **http_debug** to be `true`.
* **http_open_timeout** sets timeout in seconds to open new HTTP connection.
* **http_timeout** sets timeout in seconds to read data from a server.
* **gzip** enables gzip compression.
Expand Down
2 changes: 1 addition & 1 deletion lib/trino/client/faraday_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def self.faraday_client(options)
if options[:gzip]
faraday.request :gzip
end
faraday.response :logger if options[:http_debug]
faraday.response :logger, options[:http_debug_logger] if options[:http_debug]
faraday.adapter Faraday.default_adapter
end

Expand Down
38 changes: 38 additions & 0 deletions spec/statement_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,44 @@
end
end

describe "http_debug_logger" do
it "logs to the custom logger" do
log_output = StringIO.new
custom_logger = Logger.new(log_output)
custom_logger.formatter = proc { |_, _, _, msg| "[CUSTOM] #{msg}\n" }

stub_request(:post, "localhost/v1/statement").
to_return(body: response_json.to_json)

f = Trino::Client.faraday_client(server: "localhost", http_debug: true, http_debug_logger: custom_logger)
f.post("/v1/statement", "select 1")

expect(log_output.string).to include("[CUSTOM]")
end

it "logs to stdout when http_debug_logger is not provided" do
stub_request(:post, "localhost/v1/statement").
to_return(body: response_json.to_json)

f = Trino::Client.faraday_client(server: "localhost", http_debug: true)

expect { f.post("/v1/statement", "select 1") }.to output.to_stdout_from_any_process
end

it "does not log when http_debug is not set" do
log_output = StringIO.new
custom_logger = Logger.new(log_output)

stub_request(:post, "localhost/v1/statement").
to_return(body: response_json.to_json)

f = Trino::Client.faraday_client(server: "localhost", http_debug_logger: custom_logger)
f.post("/v1/statement", "select 1")

expect(log_output.string).to be_empty
end
end

describe "ssl" do
it "is disabled by default" do
f = Query.__send__(:faraday_client, {
Expand Down
Loading