Sha256: 7461b61d1109518919cc380c76ab9207490703eed077e256db40d6f69051b957

Contents?: true

Size: 1.88 KB

Versions: 17

Compression:

Stored size: 1.88 KB

Contents

module Logtail
  module Integrations
    module Rails
      # Disables the default rail's rack logging. Note, we cannot simply uninstall this rack
      # middleware because rails couples this with ActiveSupport instrumentation. As such,
      # we simply disable the logger and let our Rack middleware handle the logging.
      #
      # See: https://github.com/rails/rails/blob/80e66cc4d90bf8c15d1a5f6e3152e90147f00772/railties/lib/rails/rack/logger.rb#L34
      #
      # @private
      class RackLogger < Integrator

        # @private
        module InstanceMethods
          LOGGER = ::Logger.new(nil)

          def self.included(klass)
            klass.class_eval do
              private

              if ::Rails::VERSION::MAJOR == 3
                # Rails 3.2 calls Rails.logger directly in call_app, so we
                # will just replace it with a version that doesn't
                def call_app(_, env)
                  # Put some space between requests in development logs.
                  if ::Rails.env.development?
                    ::Rails.logger.info ''
                    ::Rails.logger.info ''
                  end
                  @app.call(env)
                ensure
                  ActiveSupport::LogSubscriber.flush_all!
                end
              end

              # Rails > 3.2 uses a logger method. Muting logs is accomplished by
              # passing a dummy logger instance with a nil log device.
              def logger
                LOGGER
              end
            end
          end
        end

        def initialize
          require "rails/rack/logger"
        rescue LoadError => e
          raise RequirementNotMetError.new(e.message)
        end

        def integrate!
          return true if ::Rails::Rack::Logger.include?(InstanceMethods)

          ::Rails::Rack::Logger.send(:include, InstanceMethods)
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
logtail-rails-0.2.8 lib/logtail-rails/rack_logger.rb
logtail-rails-0.2.7 lib/logtail-rails/rack_logger.rb
logtail-rails-0.2.6 lib/logtail-rails/rack_logger.rb
logtail-rails-0.2.5 lib/logtail-rails/rack_logger.rb
logtail-rails-0.2.4 lib/logtail-rails/rack_logger.rb
logtail-rails-0.2.3 lib/logtail-rails/rack_logger.rb
logtail-rails-0.2.2 lib/logtail-rails/rack_logger.rb
logtail-rails-0.2.1 lib/logtail-rails/rack_logger.rb
logtail-rails-0.1.8 lib/logtail-rails/rack_logger.rb
logtail-rails-0.1.7 lib/logtail-rails/rack_logger.rb
logtail-rails-0.1.6 lib/logtail-rails/rack_logger.rb
logtail-rails-0.1.5 lib/logtail-rails/rack_logger.rb
logtail-rails-0.1.4 lib/logtail-rails/rack_logger.rb
logtail-rails-0.1.3 lib/logtail-rails/rack_logger.rb
logtail-rails-0.1.2 lib/logtail-rails/rack_logger.rb
logtail-rails-0.1.1 lib/logtail-rails/rack_logger.rb
logtail-rails-0.1.0 lib/logtail-rails/rack_logger.rb