summaryrefslogtreecommitdiff
path: root/lib/gitlab_net.rb
diff options
context:
space:
mode:
authorJacob Vosmaer (GitLab) <jacob@gitlab.com>2018-03-19 11:58:59 +0000
committerDouwe Maan <douwe@gitlab.com>2018-03-19 11:58:59 +0000
commitb8a5e52193b7d02de4802b589e098bbbfa0ec425 (patch)
tree30833503feb797f8610b21f2475c04e959b0ebac /lib/gitlab_net.rb
parent355e70e08b9180456ef57fb79a2c3b5654f85479 (diff)
downloadgitlab-shell-b8a5e52193b7d02de4802b589e098bbbfa0ec425.tar.gz
Switch to structured logging
Diffstat (limited to 'lib/gitlab_net.rb')
-rw-r--r--lib/gitlab_net.rb12
1 files changed, 5 insertions, 7 deletions
diff --git a/lib/gitlab_net.rb b/lib/gitlab_net.rb
index a5736d6..c93cf9a 100644
--- a/lib/gitlab_net.rb
+++ b/lib/gitlab_net.rb
@@ -190,7 +190,7 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
end
def request(method, url, params = {}, options = {})
- $logger.debug "Performing #{method.to_s.upcase} #{url}"
+ $logger.debug('Performing request', method: method.to_s.upcase, url: url)
uri = URI.parse(url)
@@ -201,18 +201,16 @@ class GitlabNet # rubocop:disable Metrics/ClassLength
start_time = Time.new
response = http.start { http.request(request) }
rescue => e
- $logger.warn "Failed to connect to internal API <#{method.to_s.upcase} #{url}>: #{e.inspect}"
+ $logger.warn('Failed to connect to internal API', method: method.to_s.upcase, url: url, error: e)
raise ApiUnreachableError
ensure
- $logger.info do
- sprintf('%s %s %0.5f', method.to_s.upcase, url, Time.new - start_time) # rubocop:disable Style/FormatString
- end
+ $logger.info('finished HTTP request', method: method.to_s.upcase, url: url, duration: Time.new - start_time)
end
if response.code == "200"
- $logger.debug "Received response #{response.code} => <#{response.body}>."
+ $logger.debug('Received response', code: response.code, body: response.body)
else
- $logger.error "API call <#{method.to_s.upcase} #{url}> failed: #{response.code} => <#{response.body}>."
+ $logger.error('API call failed', method: method.to_s.upcase, url: url, code: response.code, body: response.body)
end
response