A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.aws.amazon.com/sdkforruby/api/Aws/Log/Formatter.html below:

Formatter — AWS SDK for Ruby V2

You are viewing documentation for version 2 of the AWS SDK for Ruby. Version 3 documentation can be found here.

Class: Aws::Log::Formatter
Inherits:
Object show all
Defined in:
aws-sdk-core/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)
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.

Instance Attribute Summary collapse Class Method Summary collapse Instance Method Summary collapse Constructor Details #initialize(pattern, options = {}) ⇒ Formatter

Returns a new instance of Formatter.

86
87
88
89
90
# File 'aws-sdk-core/lib/aws-sdk-core/log/formatter.rb', line 86

def initialize(pattern, options = {})
  @pattern = pattern
  @param_formatter = ParamFormatter.new(options)
  @param_filter = ParamFilter.new(options)
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.

104
105
106
107
108
109
110
# File 'aws-sdk-core/lib/aws-sdk-core/log/formatter.rb', line 104

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
93
94
95
# File 'aws-sdk-core/lib/aws-sdk-core/log/formatter.rb', line 93

def pattern
  @pattern
end
Class Method Details .colored(options = {}) ⇒ Formatter

The default log format with ANSI colors.

231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'aws-sdk-core/lib/aws-sdk-core/log/formatter.rb', line 231

def colored(options = {})
  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", options)
end
.default(options = {}) ⇒ Formatter
194
195
196
197
198
199
200
201
202
203
204
# File 'aws-sdk-core/lib/aws-sdk-core/log/formatter.rb', line 194

def default(options = {})
  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", options)
end
.short(options = {}) ⇒ Formatter

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

214
215
216
217
218
219
220
221
222
# File 'aws-sdk-core/lib/aws-sdk-core/log/formatter.rb', line 214

def short(options = {})
  pattern = []
  pattern << "[:client_class"
  pattern << ":http_response_status_code"
  pattern << ":time]"
  pattern << ":operation"
  pattern << ":error_class"
  Formatter.new(pattern.join(' ') + "\n", options)
end
Instance Method Details #format(response) ⇒ String

Given a resopnse, this will format a log message and return it as a string according to #pattern.

99
100
101
# File 'aws-sdk-core/lib/aws-sdk-core/log/formatter.rb', line 99

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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4