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

Parameters:

  • app (Faraday::Middleware)

    The middleware to nest this one in

  • logger (Logger)

    The logger to be used

  • options (Hash) (defaults to: {})

    a customizable set of options

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

Returns:

  • (Boolean)

    If the headers will be logged or not. Defaults to `false`


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

Returns:

  • (Logger)

    The configured logger


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`

Parameters:

  • env (Faraday::Env)

    The current env object


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

Parameters:

  • env (Faraday::Env)

    The current env object


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