Class: Seahorse::Client::Logging::Formatter Private

Inherits:
Object
  • Object
show all
Defined in:
lib/seahorse/client/logging/formatter.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A log formatter receives a Response object and return a log message as a string. When you construct a Formatter, you provide a pattern string with substitutions.

pattern = ':operation :http_response_status_code :time'
formatter = Seahorse::Client::Logging::Formatter.new(pattern)
formatter.format(response)
#=> 'get_bucket 200 0.0352'

# Canned Formatters

Instead of providing your own pattern, you can choose a canned log formatter.

# Pattern Substitutions

You can put any of these placeholders into you pattern.

* `:client_class` - The name of the client class.

* `:operation` - The name of the client request method.

* `:request_params` - The user provided request parameters. Long
  strings are truncated/summarized if they exceed the
  {#max_string_size}.  Other objects are inspected.

* `:time` - The total time in seconds spent on the
  request.  This includes client side time spent building
  the request and parsing the response.

* `:retries` - The number of times a client request was retried.

* `:http_request_method` - The http request verb, e.g., `POST`,
  `PUT`, `GET`, etc.

* `:http_request_endpoint` - The request endpoint.  This includes
   the scheme, host and port, but not the path.

* `:http_request_scheme` - This is replaced by `http` or `https`.

* `:http_request_host` - The host name of the http request
  endpoint (e.g. 's3.amazon.com').

* `:http_request_port` - The port number (e.g. '443' or '80').

* `:http_request_headers` - The http request headers, inspected.

* `:http_request_body` - The http request payload.

* `:http_response_status_code` - The http response status
  code, e.g., `200`, `404`, `500`, etc.

* `:http_response_headers` - The http response headers, inspected.

* `:http_response_body` - The http response body contents.

* `:error_class`

* `:error_message`

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, options = {}) ⇒ Formatter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Formatter

Parameters:

  • pattern (String)

    The log format pattern should be a string and may contain substitutions.

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :max_string_size (Integer) — default: 1000

    When summarizing request parameters, strings longer than this value will be truncated.



82
83
84
85
# File 'lib/seahorse/client/logging/formatter.rb', line 82

def initialize(pattern, options = {})
  @pattern = pattern
  @max_string_size = options[:max_string_size] || 1000
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object (private)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



109
110
111
112
113
114
115
# File 'lib/seahorse/client/logging/formatter.rb', line 109

def method_missing(method_name, *args)
  if method_name.to_s.chars.first == '_'
    ":#{method_name.to_s[1..-1]}"
  else
    super
  end
end

Instance Attribute Details

#max_string_sizeInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Integer)


91
92
93
# File 'lib/seahorse/client/logging/formatter.rb', line 91

def max_string_size
  @max_string_size
end

#patternString (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)


88
89
90
# File 'lib/seahorse/client/logging/formatter.rb', line 88

def pattern
  @pattern
end

Class Method Details

.coloredFormatter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The default log format with ANSI colors.

Examples:

A sample of the colored format (sans the ansi colors).


[ClientClass 200 0.580066 0 retries] list_objects(:bucket_name => 'bucket')

Returns:



296
297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/seahorse/client/logging/formatter.rb', line 296

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

.defaultFormatter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The default log format.

Examples:

A sample of the default format.


[ClientClass 200 0.580066 0 retries] list_objects(:bucket_name => 'bucket')

Returns:



257
258
259
260
261
262
263
264
265
266
267
# File 'lib/seahorse/client/logging/formatter.rb', line 257

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

.shortFormatter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The short log format. Similar to default, but it does not inspect the request params or report on retries.

Examples:

A sample of the short format


[ClientClass 200 0.494532] list_buckets

Returns:



278
279
280
281
282
283
284
285
286
# File 'lib/seahorse/client/logging/formatter.rb', line 278

def short
  pattern = []
  pattern << "[:client_class"
  pattern << ":http_response_status_code"
  pattern << ":time]"
  pattern << ":operation"
  pattern << ":error_class"
  Formatter.new(pattern.join(' ') + "\n")
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


102
103
104
# File 'lib/seahorse/client/logging/formatter.rb', line 102

def eql?(other)
  other.is_a?(self.class) and other.pattern == self.pattern
end

#format(response) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Given a Response, this will format a log message and return it

as a string.

Parameters:

Returns:

  • (String)


97
98
99
# File 'lib/seahorse/client/logging/formatter.rb', line 97

def format(response)
  pattern.gsub(/:(\w+)/) {|sym| send("_#{sym[1..-1]}", response) }
end