Class: Aws::Log::Formatter
- Inherits:
-
Object
- Object
- Aws::Log::Formatter
- Defined in:
- lib/aws-sdk-core/log/formatter.rb
Overview
A log formatter generates a string for logging from a response. This accomplished with a log pattern string:
pattern = ':operation :http_response_status_code :time'
formatter = Aws::Log::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.
* `:region` - The region configured for the client.
* `: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
- #pattern ⇒ String readonly
Class Method Summary collapse
-
.colored(options = {}) ⇒ Formatter
The default log format with ANSI colors.
-
.default(options = {}) ⇒ Formatter
The default log format.
-
.short(options = {}) ⇒ Formatter
The short log format.
Instance Method Summary collapse
-
#format(response) ⇒ String
Given a response, this will format a log message and return it as a string according to #pattern.
-
#initialize(pattern, options = {}) ⇒ Formatter
constructor
A new instance of Formatter.
- #method_missing(method_name, *args) ⇒ Object private
Constructor Details
#initialize(pattern, options = {}) ⇒ Formatter
Returns a new instance of Formatter.
93 94 95 96 97 |
# File 'lib/aws-sdk-core/log/formatter.rb', line 93 def initialize(pattern, = {}) @pattern = pattern @param_formatter = ParamFormatter.new() @param_filter = ParamFilter.new() end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
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.
111 112 113 114 115 116 117 |
# File 'lib/aws-sdk-core/log/formatter.rb', line 111 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
#pattern ⇒ String (readonly)
100 101 102 |
# File 'lib/aws-sdk-core/log/formatter.rb', line 100 def pattern @pattern end |
Class Method Details
.colored(options = {}) ⇒ Formatter
The default log format with ANSI colors.
249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/aws-sdk-core/log/formatter.rb', line 249 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 |
.default(options = {}) ⇒ Formatter
The default log format.
212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/aws-sdk-core/log/formatter.rb', line 212 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 |
.short(options = {}) ⇒ Formatter
The short log format. Similar to default, but it does not inspect the request params or report on retries.
232 233 234 235 236 237 238 239 240 |
# File 'lib/aws-sdk-core/log/formatter.rb', line 232 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
#format(response) ⇒ String
Given a response, this will format a log message and return it as a
string according to {#pattern}.
106 107 108 |
# File 'lib/aws-sdk-core/log/formatter.rb', line 106 def format(response) pattern.gsub(/:(\w+)/) { |sym| send("_#{sym[1..-1]}", response) } end |