Class: EnterpriseSearch::ExceptionTracking
- Inherits:
-
Object
- Object
- EnterpriseSearch::ExceptionTracking
- Defined in:
- lib/stubs/enterprise_search/exception_tracking.rb
Class Method Summary collapse
- .capture_message(message, context = {}) ⇒ Object
- .generate_error_message(exception, message, context) ⇒ Object
- .generate_stack_trace(exception) ⇒ Object
- .log_exception(exception, message = nil, context: nil, logger: AppConfig.connectors_logger) ⇒ Object
Class Method Details
.capture_message(message, context = {}) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/stubs/enterprise_search/exception_tracking.rb', line 9 def self.(, context = {}) AppConfig.connectors_logger.error { "Error: #{}. Context: #{context.inspect}" } # When the method is called from a rescue block, our return value may leak outside of its # intended scope, so let's explicitly return nil here to be safe. nil end |
.generate_error_message(exception, message, context) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/stubs/enterprise_search/exception_tracking.rb', line 23 def self.(exception, , context) context = { :message_id => exception.id }.merge(context || {}) if exception.respond_to?(:id) = context && "Context: #{context.inspect}" ['Exception', , exception.class.to_s, exception., ] .compact .map { |part| part.to_s.dup.force_encoding('UTF-8') } .join(': ') end |
.generate_stack_trace(exception) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/stubs/enterprise_search/exception_tracking.rb', line 32 def self.generate_stack_trace(exception) = exception. cause = exception while cause.cause != cause && (cause = cause.cause) << "Cause:\n#{cause.}" end .dup.force_encoding('UTF-8') end |
.log_exception(exception, message = nil, context: nil, logger: AppConfig.connectors_logger) ⇒ Object
17 18 19 20 21 |
# File 'lib/stubs/enterprise_search/exception_tracking.rb', line 17 def self.log_exception(exception, = nil, context: nil, logger: AppConfig.connectors_logger) logger.error { } if logger.error { generate_stack_trace(exception) } logger.error { "Context: #{context.inspect}" } if context end |