Module: Ahoy::LoggerSilencer

Extended by:
ActiveSupport::Concern
Defined in:
lib/ahoy/logger_silencer.rb

Instance Method Summary collapse

Instance Method Details

#add_with_threadsafety(severity, message = nil, progname = nil, &block) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/ahoy/logger_silencer.rb', line 33

def add_with_threadsafety(severity, message = nil, progname = nil, &block)
  if (defined?(@logdev) && @logdev.nil?) || (severity || UNKNOWN) < level
    true
  else
    add_without_threadsafety(severity, message, progname, &block)
  end
end

#level_with_threadsafetyObject



29
30
31
# File 'lib/ahoy/logger_silencer.rb', line 29

def level_with_threadsafety
  thread_level || level_without_threadsafety
end

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

Silences the logger for the duration of the block.



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ahoy/logger_silencer.rb', line 42

def silence_logger(temporary_level = Logger::ERROR)
  if silencer
    begin
      self.thread_level = temporary_level
      yield self
    ensure
      self.thread_level = nil
    end
  else
    yield self
  end
end

#thread_levelObject



21
22
23
# File 'lib/ahoy/logger_silencer.rb', line 21

def thread_level
  Thread.current[thread_hash_level_key]
end

#thread_level=(level) ⇒ Object



25
26
27
# File 'lib/ahoy/logger_silencer.rb', line 25

def thread_level=(level)
  Thread.current[thread_hash_level_key] = level
end