mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
WIP: Add option for a custom log proc.
If `:log_proc` is passed, then rest-client will not output any log messages itself, but will instead call the proc with an event type and a hash of data that should be useful in outputting log messages. Folks can use this to implement log levels, redaction, etc.
This commit is contained in:
parent
4130d0e00f
commit
43af5cc7ec
1 changed files with 13 additions and 0 deletions
|
@ -138,6 +138,8 @@ module RestClient
|
|||
end
|
||||
|
||||
@log = args[:log]
|
||||
@log_proc = args[:log_proc]
|
||||
|
||||
@tf = nil # If you are a raw request, this is your tempfile
|
||||
@max_redirects = args[:max_redirects] || 10
|
||||
@processed_headers = make_headers headers
|
||||
|
@ -540,6 +542,11 @@ module RestClient
|
|||
def log_request
|
||||
return unless log
|
||||
|
||||
if @log_proc
|
||||
@log_proc.call(:request, {request: self, headers: processed_headers})
|
||||
return
|
||||
end
|
||||
|
||||
out = []
|
||||
|
||||
out << "RestClient.#{method} #{redacted_url.inspect}"
|
||||
|
@ -551,6 +558,11 @@ module RestClient
|
|||
def log_response res
|
||||
return unless log
|
||||
|
||||
if @log_proc
|
||||
@log_proc.call(:request, {request: self, response: res})
|
||||
return
|
||||
end
|
||||
|
||||
size = if @raw_response
|
||||
File.size(@tf.path)
|
||||
else
|
||||
|
@ -790,6 +802,7 @@ module RestClient
|
|||
size += chunk.size
|
||||
if log
|
||||
if size == 0
|
||||
# TODO XXX
|
||||
log << "%s %s done (0 length file)\n" % [@method, @url]
|
||||
elsif total == 0
|
||||
log << "%s %s (zero content length)\n" % [@method, @url]
|
||||
|
|
Loading…
Reference in a new issue