class Seahorse::Client::Logging::Formatter
* ‘:error_message`
* `:error_class`
* `:http_response_body` - The http response body contents.
* `:http_response_headers` - The http response headers, inspected.
code, e.g., `200`, `404`, `500`, etc.
* `:http_response_status_code` - The http response status
* `:http_request_body` - The http request payload.
* `:http_request_headers` - The http request headers, inspected.
* `:http_request_port` - The port number (e.g. ’443’ or ‘80’).
endpoint (e.g. ‘s3.amazon.com’).
* ‘:http_request_host` - The host name of the http request
* `:http_request_scheme` - This is replaced by `http` or `https`.
the scheme, host and port, but not the path.
* `:http_request_endpoint` - The request endpoint. This includes
`PUT`, `GET`, etc.
* `:http_request_method` - The http request verb, e.g., `POST`,
* `:retries` - The number of times a client request was retried.
the request and parsing the response.
request. This includes client side time spent building
* `:time` - The total time in seconds spent on the
{#max_string_size}. Other objects are inspected.
strings are truncated/summarized if they exceed the
* `:request_params` - The user provided request parameters. Long
* `:operation` - The name of the client request method.
* `:client_class` - The name of the client class.
You can put any of these placeholders into you pattern.
# Pattern Substitutions
* {Formatter.short}
* {Formatter.colored}
* {Formatter.default}
formatter.
Instead of providing your own pattern, you can choose a canned log
# Canned Formatters
#=> ’get_bucket 200 0.0352’
formatter.format(response)
formatter = Seahorse::Client::Logging::Formatter.new(pattern)
pattern = ‘:operation :http_response_status_code :time’
a pattern string with substitutions.
a log message as a string. When you construct a {Formatter}, you provide
A log formatter receives a {Response} object and return
def _client_class(response)
def _client_class(response) response.context.client.class.name end
def _error_class(response)
def _error_class(response) response.error ? response.error.class.name : '' end
def _error_message(response)
def _error_message(response) response.error ? response.error.message : '' end
def _http_request_body(response)
def _http_request_body(response) summarize_value(response.context.http_request.body_contents) end
def _http_request_endpoint(response)
def _http_request_endpoint(response) response.context.http_request.endpoint.to_s end
def _http_request_headers(response)
def _http_request_headers(response) response.context.http_request.headers.inspect end
def _http_request_host(response)
def _http_request_host(response) response.context.http_request.endpoint.host end
def _http_request_method(response)
def _http_request_method(response) response.context.http_request.http_method end
def _http_request_port(response)
def _http_request_port(response) response.context.http_request.endpoint.port.to_s end
def _http_request_scheme(response)
def _http_request_scheme(response) response.context.http_request.endpoint.scheme end
def _http_response_body(response)
def _http_response_body(response) if response.context.http_response.body.respond_to?(:rewind) summarize_value(response.context.http_response.body_contents) else '' end end
def _http_response_headers(response)
def _http_response_headers(response) response.context.http_response.headers.inspect end
def _http_response_status_code(response)
def _http_response_status_code(response) response.context.http_response.status_code.to_s end
def _operation(response)
def _operation(response) response.context.operation_name end
def _request_params(response)
def _request_params(response) summarize_hash(response.context.params) end
def _retries(response)
def _retries(response) response.context.retries end
def _time(response)
def _time(response) duration = response.context[:logging_completed_at] - response.context[:logging_started_at] ("%.06f" % duration).sub(/0+$/, '') end
def colored
-
(Formatter)
-
Other tags:
- Example: A sample of the colored format (sans the ansi colors). -
def colored bold = "\x1b[1m" color = "\x1b[34m" reset = "\x1b[0m" pattern = [] pattern << "#{bold}#{color}[:client_class" pattern << ":http_response_status_code" pattern << ":time" pattern << ":retries retries]#{reset}#{bold}" pattern << ":operation(:request_params)" pattern << ":error_class" pattern << ":error_message#{reset}" Formatter.new(pattern.join(' ') + "\n") end
def default
-
(Formatter)
-
Other tags:
- Example: A sample of the default format. -
def default pattern = [] pattern << "[:client_class" pattern << ":http_response_status_code" pattern << ":time" pattern << ":retries retries]" pattern << ":operation(:request_params)" pattern << ":error_class" pattern << ":error_message" Formatter.new(pattern.join(' ') + "\n") end
def eql?(other)
- Api: - private
def eql?(other) other.is_a?(self.class) and other.pattern == self.pattern end
def format(response)
-
(String)
-
Parameters:
-
response
(Response
) --
def format(response) pattern.gsub(/:(\w+)/) {|sym| send("_#{sym[1..-1]}", response) } end
def initialize(pattern, options = {})
(**options)
-
:max_string_size
(Integer
) -- When summarizing
Parameters:
-
pattern
(String
) -- The log format pattern should be a string
def initialize(pattern, options = {}) @pattern = pattern @max_string_size = options[:max_string_size] || 1000 end
def method_missing(method_name, *args)
def method_missing(method_name, *args) if method_name.to_s.chars.first == '_' ":#{method_name.to_s[1..-1]}" else super end end
def short
-
(Formatter)
-
Other tags:
- Example: A sample of the short format -
def short pattern = [] pattern << "[:client_class" pattern << ":http_response_status_code" pattern << ":time]" pattern << ":operation" pattern << ":error_class" Formatter.new(pattern.join(' ') + "\n") end
def summarize_array array
-
(String)
-
Parameters:
-
array
(Array
) --
def summarize_array array "[" + array.map{|v| summarize_value(v) }.join(",") + "]" end
def summarize_file path
-
(String)
-
Parameters:
-
path
(String
) --
def summarize_file path "#<File:#{path} (#{File.size(path)} bytes)>" end
def summarize_hash(hash)
-
(String)
-
Parameters:
-
hash
(Hash
) --
def summarize_hash(hash) hash.keys.first.is_a?(String) ? summarize_string_hash(hash) : summarize_symbol_hash(hash) end
def summarize_string str
-
(String)
-
Parameters:
-
str
(String
) --
def summarize_string str max = max_string_size if str.size > max "#<String #{str[0...max].inspect} ... (#{str.size} bytes)>" else str.inspect end end
def summarize_string_hash(hash)
def summarize_string_hash(hash) hash.map do |key,v| "#{key.inspect}=>#{summarize_value(v)}" end.join(",") end
def summarize_symbol_hash(hash)
def summarize_symbol_hash(hash) hash.map do |key,v| "#{key}:#{summarize_value(v)}" end.join(",") end
def summarize_value value
-
(String)
-
Parameters:
-
value
(Object
) --
def summarize_value value case value when String then summarize_string(value) when Hash then '{' + summarize_hash(value) + '}' when Array then summarize_array(value) when File then summarize_file(value.path) when Pathname then summarize_file(value) else value.inspect end end