Class: Log4rExceptionable::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/log4r-exceptionable/configuration.rb

Overview

Configuration for the failure backends that log exceptions with log4r

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.context_exclusionsObject

blacklist of context keys (e.g. keys in rack env) to exclude in log4r context when logging



17
18
19
# File 'lib/log4r-exceptionable/configuration.rb', line 17

def context_exclusions
  @context_exclusions
end

.context_inclusionsObject

whitelist of context keys (e.g. keys in rack env) to include in log4r context when logging



15
16
17
# File 'lib/log4r-exceptionable/configuration.rb', line 15

def context_inclusions
  @context_inclusions
end

.failsafe_loggingObject

Swallow exceptions raised by the call to the logger, printing to stderr, defaults to true



19
20
21
# File 'lib/log4r-exceptionable/configuration.rb', line 19

def failsafe_logging
  @failsafe_logging
end

.log_levelObject

The level to log exceptions



13
14
15
# File 'lib/log4r-exceptionable/configuration.rb', line 13

def log_level
  @log_level
end

.rack_failure_loggerObject

required - default loggers used if source logger not available



9
10
11
# File 'lib/log4r-exceptionable/configuration.rb', line 9

def rack_failure_logger
  @rack_failure_logger
end

.resque_failure_loggerObject

required - default loggers used if source logger not available



9
10
11
# File 'lib/log4r-exceptionable/configuration.rb', line 9

def resque_failure_logger
  @resque_failure_logger
end

.sidekiq_failure_loggerObject

required - default loggers used if source logger not available



9
10
11
# File 'lib/log4r-exceptionable/configuration.rb', line 9

def sidekiq_failure_logger
  @sidekiq_failure_logger
end

.use_source_loggerObject

Allows one to force use of default loggers by setting to false



11
12
13
# File 'lib/log4r-exceptionable/configuration.rb', line 11

def use_source_logger
  @use_source_logger
end

Class Method Details

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/log4r-exceptionable/configuration.rb', line 27

def self.configure
  yield self

  if ! self.rack_failure_logger && ! self.resque_failure_logger && ! self.sidekiq_failure_logger
    raise "log4r-exceptionable requires a rack_failure_logger or resque_failure_logger or sidekiq_failure_logger"
  end

  if self.rack_failure_logger
    self.set_logger(:rack_failure_logger)
  end
  
  if self.resque_failure_logger
    self.set_logger(:resque_failure_logger)
  end
  
  if self.sidekiq_failure_logger
    self.set_logger(:sidekiq_failure_logger)
  end
  
  self.context_inclusions = Set.new(self.context_inclusions) if self.context_inclusions
  self.context_exclusions = Set.new(self.context_exclusions) if self.context_exclusions

  raise "Invalid log level: #{self.log_level}" unless Log4r::LNAMES.include?(self.log_level.to_s.upcase)
  self.log_level = self.log_level.to_sym
end

.set_logger(accessor) ⇒ Object



53
54
55
56
57
58
# File 'lib/log4r-exceptionable/configuration.rb', line 53

def self.set_logger(accessor)
  if ! self.send(accessor).instance_of?(Log4r::Logger)
    name = self.send(accessor).to_s
    self.send("#{accessor}=", Log4r::Logger[name] || Log4r::Logger.new(name))
  end
end