Sha256: b6621bb456b38220d234c7bc4c4219e7f4546813cce9d5f6b87b9d602882aebb

Contents?: true

Size: 711 Bytes

Versions: 1

Compression:

Stored size: 711 Bytes

Contents

require "active_record"
require "nokogiri"
require "zeitwerk"

loader = Zeitwerk::Loader.for_gem
loader.collapse("#{__dir__}/rails_api_logger")
loader.do_not_eager_load("#{__dir__}/generators")
loader.setup

class RailsApiLogger
  class Error < StandardError; end

  def initialize(loggable = nil)
    @loggable = loggable
  end

  def call(url, request)
    log = OutboundRequestLog.from_request(request, loggable: @loggable)
    yield.tap do |response|
      log.from_response(response)
    end
  rescue => e
    log.response_body = {error: e.message}
    raise
  ensure
    log.ended_at = Time.current
    log.save!
  end
end

ActiveSupport.on_load(:action_controller) do
  include InboundRequestsLogger
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_api_logger-0.6.1 lib/rails_api_logger.rb