Class: Aviator::Logger

Inherits:
Faraday::Response::Middleware show all
Extended by:
Forwardable
Defined in:
lib/puppet/feature/aviator/core/logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Faraday::Middleware

dependency, inherited, loaded?, new

Methods included from Faraday::MiddlewareRegistry

#fetch_middleware, #load_middleware, #lookup_middleware, #middleware_mutex, #register_middleware

Constructor Details

#initialize(app, logger = nil) ⇒ Logger

Returns a new instance of Logger.



6
7
8
9
10
11
12
# File 'lib/puppet/feature/aviator/core/logger.rb', line 6

def initialize(app, logger=nil)
  super(app)
  @logger = logger || begin
    require 'logger'
    ::Logger.new(self.class::LOG_FILE_PATH)
  end
end

Class Method Details

.configure(log_file_path) ⇒ Object



33
34
35
36
37
38
# File 'lib/puppet/feature/aviator/core/logger.rb', line 33

def self.configure(log_file_path)
  # Return a subclass with its logfile path set. This
  # must be done so that different sessions can log to
  # different paths.
  Class.new(self) { const_set('LOG_FILE_PATH', log_file_path) }
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
# File 'lib/puppet/feature/aviator/core/logger.rb', line 18

def call(env)
  info(env[:method].to_s.upcase) { env[:url].to_s }
  debug('REQ_HEAD') { dump_headers env[:request_headers] }
  debug('REQ_BODY') { dump_body env[:body] }
  super
end

#on_complete(env) ⇒ Object



26
27
28
29
30
# File 'lib/puppet/feature/aviator/core/logger.rb', line 26

def on_complete(env)
  info('STATUS') { env[:status].to_s }
  debug('RES_HEAD') { dump_headers env[:response_headers] }
  debug('RES_BODY') { dump_body env[:body] }
end