Module: LoggerSilence

Extended by:
ActiveSupport::Concern
Included in:
ActiveSupport::Logger
Defined in:
lib/active_support/logger_silence.rb

Instance Method Summary collapse

Methods included from ActiveSupport::Concern

append_features, extended, included

Instance Method Details

#after_initializeObject


14
15
16
# File 'lib/active_support/logger_silence.rb', line 14

def after_initialize
  @local_levels = ThreadSafe::Cache.new(:initial_capacity => 2)
end

#levelObject


22
23
24
# File 'lib/active_support/logger_silence.rb', line 22

def level
  local_levels[local_log_id] || super
end

#local_log_idObject


18
19
20
# File 'lib/active_support/logger_silence.rb', line 18

def local_log_id
  Thread.current.__id__
end

#silence(temporary_level = Logger::ERROR) ⇒ Object

Silences the logger for the duration of the block.


27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/active_support/logger_silence.rb', line 27

def silence(temporary_level = Logger::ERROR)
  if silencer
    begin
      old_local_level            = local_levels[local_log_id]
      local_levels[local_log_id] = temporary_level

      yield self
    ensure
      if old_local_level
        local_levels[local_log_id] = old_local_level
      else
        local_levels.delete(local_log_id)
      end
    end
  else
    yield self
  end
end