Sha256: f8c93ade8325e938724b02597d2f684d678d326ccb642d1b81a33e303c0f8ea7

Contents?: true

Size: 1.37 KB

Versions: 22

Compression:

Stored size: 1.37 KB

Contents

# frozen-string-literal: true

#
class Roda
  module RodaPlugins
    # The skip_common_logger plugin allows for skipping common_logger logging
    # of some requests. You pass a block when loading the plugin, and the
    # block will be called before logging each request.  The block should return
    # whether the request should be logged.
    #
    # Example:
    #
    #   # Only log server errors
    #   plugin :filter_common_logger do |result|
    #     result[0] >= 500
    #   end
    #
    #   # Don't log requests to certain paths
    #   plugin :filter_common_logger do |_|
    #     # Block is called in the same context as the route block
    #     !request.path.start_with?('/admin/')
    #   end
    module FilterCommonLogger
      def self.load_dependencies(app)
        app.plugin :common_logger
      end

      def self.configure(app, &block)
        app.send(:define_method, :_common_log_request?, &block)
        app.send(:private, :_common_log_request?)
        app.send(:alias_method, :_common_log_request?, :_common_log_request?)
      end

      module InstanceMethods
        private

        # Log request/response information in common log format to logger.
        def _roda_after_90__common_logger(result)
          super if result && _common_log_request?(result)
        end
      end
    end

    register_plugin(:filter_common_logger, FilterCommonLogger)
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
roda-3.79.0 lib/roda/plugins/filter_common_logger.rb
roda-3.78.0 lib/roda/plugins/filter_common_logger.rb
roda-3.77.0 lib/roda/plugins/filter_common_logger.rb
roda-3.76.0 lib/roda/plugins/filter_common_logger.rb
roda-3.75.0 lib/roda/plugins/filter_common_logger.rb
roda-3.74.0 lib/roda/plugins/filter_common_logger.rb
roda-3.73.0 lib/roda/plugins/filter_common_logger.rb
roda-3.72.0 lib/roda/plugins/filter_common_logger.rb
roda-3.71.0 lib/roda/plugins/filter_common_logger.rb
roda-3.70.0 lib/roda/plugins/filter_common_logger.rb
roda-3.69.0 lib/roda/plugins/filter_common_logger.rb
roda-3.68.0 lib/roda/plugins/filter_common_logger.rb
roda-3.67.0 lib/roda/plugins/filter_common_logger.rb
roda-3.66.0 lib/roda/plugins/filter_common_logger.rb
roda-3.65.0 lib/roda/plugins/filter_common_logger.rb
roda-3.64.0 lib/roda/plugins/filter_common_logger.rb
roda-3.63.0 lib/roda/plugins/filter_common_logger.rb
roda-3.62.0 lib/roda/plugins/filter_common_logger.rb
roda-3.61.0 lib/roda/plugins/filter_common_logger.rb
roda-3.60.0 lib/roda/plugins/filter_common_logger.rb