Class: Fbe::Middleware::LoggingFormatter
- Inherits:
-
Faraday::Logging::Formatter
- Object
- Faraday::Logging::Formatter
- Fbe::Middleware::LoggingFormatter
- Defined in:
- lib/fbe/middleware/logging_formatter.rb
Overview
Faraday logging formatter show verbose log for only error response
Constant Summary collapse
- AUTHORIZATION_FILTER =
[/(Authorization: )([^&]+)([^&]{5})/, '\1********\3'].freeze
Instance Method Summary collapse
-
#initialize ⇒ LoggingFormatter
constructor
A new instance of LoggingFormatter.
- #log_only_errors? ⇒ Boolean
- #request(env) ⇒ Object
- #request_with_response(env) ⇒ Object
- #response(env) ⇒ Object
Constructor Details
#initialize ⇒ LoggingFormatter
Returns a new instance of LoggingFormatter.
31 32 33 34 |
# File 'lib/fbe/middleware/logging_formatter.rb', line 31 def initialize(**) super filter(*AUTHORIZATION_FILTER) end |
Instance Method Details
#log_only_errors? ⇒ Boolean
60 61 62 |
# File 'lib/fbe/middleware/logging_formatter.rb', line 60 def log_only_errors? @options[:log_only_errors] end |
#request(env) ⇒ Object
36 37 38 |
# File 'lib/fbe/middleware/logging_formatter.rb', line 36 def request(env) super unless log_only_errors? end |
#request_with_response(env) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fbe/middleware/logging_formatter.rb', line 45 def request_with_response(env) oll = @options[:log_level] @options[:log_level] = :error public_send(log_level, 'request') do "#{env.method.upcase} #{apply_filters(env.url.to_s)}" end log_headers('request', env.request_headers) if log_headers?(:request) log_body('request', env[:request_body]) if env[:request_body] && log_body?(:request) public_send(log_level, 'response') { "Status #{env.status}" } log_headers('response', env.response_headers) if log_headers?(:response) log_body('response', env[:response_body]) if env[:response_body] && log_body?(:response) @options[:log_level] = oll nil end |
#response(env) ⇒ Object
40 41 42 43 |
# File 'lib/fbe/middleware/logging_formatter.rb', line 40 def response(env) return super unless log_only_errors? request_with_response(env) if env.status.nil? || env.status >= 400 end |