Sha256: 11fbefaa65ddc766a4233ccd9bfa7824b63394d59a4f591edacaed5cde6574a2
Contents?: true
Size: 1.06 KB
Versions: 2
Compression:
Stored size: 1.06 KB
Contents
# frozen_string_literal: true require 'request_store' # Requiring this file, or calling `Gecko.enable_logging` will hook into the provided # ActiveSupport::Notification hooks on requests and log ActiveRecord-style messages # on API requests. class GeckoLogSubscriber < ActiveSupport::LogSubscriber ENV_KEY = :"gecko-logger" def initialize super @odd = false end def request(event) RequestStore.store[ENV_KEY] = [] payload = event.payload request_path = payload[:request_path] if payload[:params] && payload[:verb] == :get request_path = request_path + "?" + payload[:params].to_param RequestStore.store[ENV_KEY] << request_path end name = "#{payload[:model_class]} Load (#{event.duration.round(1)}ms)" query = "#{payload[:verb].to_s.upcase} /#{request_path}" if odd? name = color(name, CYAN, true) else name = color(name, MAGENTA, true) end query = color(query, nil, true) debug(" #{name} #{query}") end def odd? @odd = !@odd end end GeckoLogSubscriber.attach_to :gecko
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
gecko-ruby-0.9.1 | lib/gecko/ext/log_subscriber.rb |
gecko-ruby-0.9.0 | lib/gecko/ext/log_subscriber.rb |