cartodb-4.42/lib/carto/http/response_logger.rb

39 lines
899 B
Ruby
Raw Normal View History

2024-04-06 13:25:13 +08:00
require 'socket'
require 'carto/configuration'
module Carto
module Http
class ResponseLogger
include Carto::Configuration
def self.enabled?
Cartodb.config[:http_client_logs]
end
def initialize(tag)
@tag = tag
@hostname = Socket.gethostname
end
def log(response)
payload = {
tag: @tag,
hostname: @hostname,
method: (response.request.options[:method] || :get).to_s, # the default typhoeus method is :get
request_url: response.request.url,
total_time: response.total_time,
response_code: response.code,
response_body_size: response.body.nil? ? 0 : response.body.size
}
logger.info(payload.to_json)
end
def logger
@@logger ||= CartoDB.unformatted_logger(log_file_path('http_client.log'))
end
end
end
end