class AWS::Core::LogFormatter


The http response body contents.
[:http_response_body]

The http response headers, inspected.
[:http_response_headers]

The http response status code (e.g. ‘200’, ‘404’, ‘500’, etc).
[:http_response_status]

The proxy uri used, or an empty string.
[:http_request_proxy_uri]

The http request headers, inspected.
[:http_request_headers]

The http request payload.
[:http_request_body]

‘/bucket_name/objects/key?versions’).
The http request uri folling the host (e.g.
[:http_request_uri]

The port number (e.g. ‘443’ or ‘80’).
[:http_request_port]

The host name of the http request endpoint (e.g. ‘s3.amazon.com’).
[:http_request_host]

This is replaced by ‘http’ or ‘https’.
[:http_request_protocol]

The HTTP request verb (e.g. ‘POST’, ‘PUT’, ‘GET’, etc).
[:http_request_method]

string.
no error was returned by the service, this will be an empty
The message of the error returned. If
[:error_message]

an empty string.
service. If no error was returned, this will be replcaed by
The class name of the error returned by the
[:error_class]

a value (event retries and retry delays).
calling the client request method, until that method returns
in decimal seconds. This time includes everything from
The time it took to generate a response, expressed
[:duration]

getting a successful response or giving up.
This value indicates how many extra attempts were made before
Throttlings and service errors trigger the automatic retry logic.
The number of times a client request was retried.
[:retry_count]

formatters {#max_string_size}. Other objects are inspected.
Long strings are truncated/summarized if they excede the log
The hash of options passed to the client request method.
[:options]

the serivce API operation (e.g. :describe_instances).
The name of the client request method. This maps to the name of
[:operation]

The AWS region name (e.g. ‘us-east-1’, ‘us-west-1’, etc)
[:region]

The AWS service name (e.g. ‘S3’, ‘EC2’, ‘SimpleDB’, etc)
[:service]

You can put any of these placeholders into you pattern.
= Pattern Substitutions
* {LogFormatter.colored}
* {LogFormatter.debug}
* {LogFormatter.short}
* {LogFormatter.default}
Here is the list of canned formatters.
AWS.config(:log_formatter => AWS::Core::LogFormatter.colored)
formatter.
Instead of providing your own pattern, you can choose a canned log
== Canned Formatters
AWS.config(:log_formatter => AWS::Core::LogFormatter.new(pattern)
pattern = ‘[REQUEST :http_status_code] :service :operation :duration’
to {AWS.config}.
repace this formatter by building your own and then passing it
AWS.config provides a {LogFormatter.default} log formatter. You can
= AWS Configuration
#=> ‘[AWS 200] EC2 get_bucket 0.0352’
formatter.format(response)
formatter = AWS::Core::LogFormatter.new(pattern)
pattern = ‘[REQUEST :http_status_code] :service :operation :duration’
a pattern string with substitutions.
a log message. When you construct a {LogFormatter}, you provide
Log formatters receive a {AWS::Core::Response} object and return
= Log Formatters

def _duration response

def _duration response
  ("%.06f" % response.duration).sub(/0+$/, '')
end

def _error_class response

def _error_class response
  response.error.class.name if response.error
end

def _error_message response

def _error_message response
  response.error.message if response.error
end

def _http_request_body response

def _http_request_body response
  response.http_request.body
end

def _http_request_headers response

def _http_request_headers response
  response.http_request.headers.inspect
end

def _http_request_host response

def _http_request_host response
  response.http_request.host
end

def _http_request_method response

def _http_request_method response
  response.http_request.http_method
end

def _http_request_port response

def _http_request_port response
  response.http_request.port
end

def _http_request_protocol response

def _http_request_protocol response
  response.http_request.use_ssl? ? 'https' : 'http'
end

def _http_request_proxy_uri response

def _http_request_proxy_uri response
  response.http_request.proxy_uri
end

def _http_request_uri response

def _http_request_uri response
  response.http_request.uri
end

def _http_response_body response

def _http_response_body response
  response.http_response.body
end

def _http_response_headers response

def _http_response_headers response
  response.http_response.headers.inspect
end

def _http_response_status response

def _http_response_status response
  response.http_response.status
end

def _operation response

def _operation response
  response.request_type
end

def _options response

def _options response
  summarize_hash(response.request_options) if response.request_options
end

def _region response

def _region response
  response.http_request.region
end

def _retry_count response

def _retry_count response
  response.retry_count
end

def _service response

def _service response
  response.http_request.class.name.split('::')[1]
end

def colored

Returns:
  • (LogFormatter) -

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}[AWS"
  pattern << ":service"
  pattern << ":http_response_status"
  pattern << ":duration"
  pattern << ":retry_count retries]#{reset}#{bold}"
  pattern << ":operation(:options)"
  pattern << ":error_class"
  pattern << ":error_message#{reset}"
  LogFormatter.new(pattern.join(' ') + "\n")
end

def debug

Returns:
  • (LogFormatter) -

Other tags:
    Example: A truncated sample of the debug format. -
def debug
  sig_pattern = []
  sig_pattern << ':region'
  sig_pattern << ':service'
  sig_pattern << ':operation'
  sig_pattern << ':duration'
  sig_pattern << ':retry_count retries'
  uri_pattern = []
  uri_pattern << ':http_request_protocol'
  uri_pattern << '://'
  uri_pattern << ':http_request_host'
  uri_pattern << '::'
  uri_pattern << ':http_request_port'
  uri_pattern << ':'
  uri_pattern << ':http_request_uri'
  line = "+" + '-' * 79 
  pattern = []
  pattern << line
  pattern << "| AWS #{sig_pattern.join(' ')}"
  pattern << line
  pattern << "|   REQUEST"
  pattern << line
  pattern << "|    METHOD: :http_request_method"
  pattern << "|       URL: #{uri_pattern.join}"
  pattern << "|   HEADERS: :http_request_headers"
  pattern << "|      BODY: :http_request_body"
  pattern << line
  pattern << "|  RESPONSE"
  pattern << line
  pattern << "|    STATUS: :http_response_status"
  pattern << "|   HEADERS: :http_response_headers"
  pattern << "|      BODY: :http_response_body"
  LogFormatter.new(pattern.join("\n") + "\n")
end

def default

Returns:
  • (LogFormatter) -

Other tags:
    Example: A sample of the default format. -
def default
  pattern = []
  pattern << "[AWS"
  pattern << ":service"
  pattern << ":http_response_status"
  pattern << ":duration"
  pattern << ":retry_count retries]"
  pattern << ":operation(:options)"
  pattern << ":error_class"
  pattern << ":error_message"
  LogFormatter.new(pattern.join(' ') + "\n")
end

def eql? other

Other tags:
    Private: -
def eql? other
  other.is_a?(self.class) and other.pattern == self.pattern
end

def format response

Returns:
  • (String) -

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

def initialize pattern, options = {}

Options Hash: (**options)
  • :max_string_size (Integer) --

Parameters:
  • options (Hash) --
  • 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

Returns:
  • (LogFormatter) -

Other tags:
    Example: A sample of the short format -
def short
  pattern = []
  pattern << "[AWS"
  pattern << ":service"
  pattern << ":http_response_status"
  pattern << ":duration]"
  pattern << ":operation"
  pattern << ":error_class"
  LogFormatter.new(pattern.join(' ') + "\n")
end

def summarize_array array

Returns:
  • (String) -

Parameters:
  • array (Array) --
def summarize_array array
  "[" + array.map{|v| summarize_value(v) }.join(",") + "]"
end

def summarize_file path

Returns:
  • (String) -

Parameters:
  • path (String) --
def summarize_file path
  "#<File:#{path} (#{File.size(path)} bytes)>"
end

def summarize_hash hash

Returns:
  • (String) -

Parameters:
  • hash (Hash) --
def summarize_hash hash
  hash.map do |key,v|
    ":#{key}=>#{summarize_value(v)}"
  end.sort.join(",")
end

def summarize_string str

Returns:
  • (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_value value

Returns:
  • (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