Class: Ciunas::Logger

Inherits:
Rails::Rack::Logger
  • Object
show all
Defined in:
lib/ciunas/logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, opts = {}) ⇒ Logger

Returns a new instance of Logger.



3
4
5
6
7
# File 'lib/ciunas/logger.rb', line 3

def initialize(app, opts = {})
  @app = app
  @opts = opts
  @opts[:silenced] ||= []
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ciunas/logger.rb', line 9

def call(env)
  if env['X-SILENCE-LOGGER'] || @opts[:silenced].any? {|m| m === env['PATH_INFO'] }
    begin
      # temporarily set the rails log level to error
      old_logger_level, Rails.logger.level = Rails.logger.level, tmp_log_level
      @app.call(env)
    ensure
      Rails.logger.level = old_logger_level
    end
  else
    super(env)
  end
end

#tmp_log_levelObject



23
24
25
26
27
28
29
# File 'lib/ciunas/logger.rb', line 23

def tmp_log_level
  if defined?(ActiveSupport::BufferedLogger::Severity::ERROR)
    ActiveSupport::BufferedLogger::Severity::ERROR
  else
    ActiveSupport::Logger::Severity::ERROR
  end
end