mirror of
https://github.com/puppetlabs/vmpooler.git
synced 2026-01-27 02:18:41 -05:00
This was partially an exercise to use middleware, but also to enable basic logging for the API by logging all the API calls to the logger.
20 lines
470 B
Ruby
20 lines
470 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Vmpooler
|
|
class API
|
|
class RequestLogger
|
|
attr_reader :app
|
|
|
|
def initialize(app, options = {})
|
|
@app = app
|
|
@logger = options[:logger]
|
|
end
|
|
|
|
def call(env)
|
|
status, headers, body = @app.call(env)
|
|
@logger.log('s', "[ ] API: Method: #{env['REQUEST_METHOD']}, Status: #{status}, Path: #{env['PATH_INFO']}, Body: #{body}")
|
|
[status, headers, body]
|
|
end
|
|
end
|
|
end
|
|
end
|