Module: Log4rExceptionable::Helper
- Included in:
- RackFailureHandler, ResqueFailureHandler, SidekiqFailureHandler
- Defined in:
- lib/log4r-exceptionable/helper.rb
Overview
Configuration for the failure backends that log exceptions with log4r
Instance Method Summary collapse
Instance Method Details
#add_context(context, key, value) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/log4r-exceptionable/helper.rb', line 28 def add_context(context, key, value) inclusions = Log4rExceptionable::Configuration.context_inclusions exclusions = Log4rExceptionable::Configuration.context_exclusions return if inclusions && ! inclusions.include?(key) if exclusions if ! exclusions.include?(key) context.put(key, value) end else context.put(key, value) end end |
#log_with_context ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/log4r-exceptionable/helper.rb', line 7 def log_with_context begin mdc = Log4r::MDC original_mdc = mdc.get_context begin yield mdc ensure # Since this is somewhat of a global map, clean the keys # we put in so other log messages don't see them mdc.get_context.keys.each do |k| mdc.remove(k) unless original_mdc.has_key?(k) end end rescue => e raise e unless Log4rExceptionable::Configuration.failsafe_logging $stderr.puts "Log4r Exceptionable could not log exception: #{e.class} #{e.}" end end |