Class: Ashikawa::Core::MinimalLogger

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/ashikawa-core/minimal_logger.rb

Overview

A more minimal logger as replacement for the very chatty Faraday logger

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, logger, options = {}) ⇒ MinimalLogger

Initialize the middleware

Options Hash (options):

  • :debug_headers (Boolean)

    Should the headers be logged. Defaults to ‘false`



28
29
30
31
32
# File 'lib/ashikawa-core/minimal_logger.rb', line 28

def initialize(app, logger, options = {})
  super(app)
  @logger        = logger
  @debug_headers = options.fetch(:debug_headers) { false }
end

Instance Attribute Details

#debug_headersBoolean (readonly)

Should HTTP headers be logged



20
21
22
# File 'lib/ashikawa-core/minimal_logger.rb', line 20

def debug_headers
  @debug_headers
end

#loggerLogger (readonly)

The logger to be used



14
15
16
# File 'lib/ashikawa-core/minimal_logger.rb', line 14

def logger
  @logger
end

Instance Method Details

#call(env) ⇒ Object

Calls the this middleware and passes on to ‘super`



38
39
40
41
# File 'lib/ashikawa-core/minimal_logger.rb', line 38

def call(env)
  logger.debug('request') { "#{env.method.upcase} #{env.url}#{dump_headers(env.request_headers)}" }
  super
end

#on_complete(env) ⇒ Object

The callback when the request was completed



47
48
49
# File 'lib/ashikawa-core/minimal_logger.rb', line 47

def on_complete(env)
  logger.debug('response') { "#{env.method.upcase} #{env.url} #{env.status}#{dump_headers(env.response_headers)}" }
end