Module: Sinatra::QuietLogger

Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-contrib-3.0.5/lib/sinatra/quiet_logger.rb

Overview

Sinatra::QuietLogger

QuietLogger extension allows you to define paths excluded from logging using the quiet_logger_prefixes setting. It is inspired from rails quiet_logger, but handles multiple paths.

Usage

Classic Application

You have to require the quiet_logger, set the prefixes and register the extension in your application.

require 'sinatra'
require 'sinatra/quiet_logger'

set :quiet_logger_prefixes, %w(css js images fonts)
register Sinatra::QuietLogger

Modular Application

The same for modular application:

require 'sinatra/base'
require 'sinatra/quiet_logger'

set :quiet_logger_prefixes, %w(css js images fonts)

class App < Sinatra::Base
  register Sinatra::QuietLogger
end

Class Method Summary collapse

Class Method Details

.registered(app) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/sinatra-contrib-3.0.5/lib/sinatra/quiet_logger.rb', line 37

def self.registered(app)
  quiet_logger_prefixes = begin
    app.settings.quiet_logger_prefixes.join('|')
  rescue StandardError
    ''
  end
  return warn('You need to specify the paths you wish to exclude from logging via `set :quiet_logger_prefixes, %w(images css fonts)`') if quiet_logger_prefixes.empty?

  const_set('QUIET_LOGGER_REGEX', %r(\A/{0,2}(?:#{quiet_logger_prefixes})))
  ::Rack::CommonLogger.prepend(
    ::Module.new do
      def log(env, *)
        super unless env['PATH_INFO'] =~ QUIET_LOGGER_REGEX
      end
    end
  )
end