Class: ChiliLogger::LoggingErrorHandler
- Inherits:
-
Object
- Object
- ChiliLogger::LoggingErrorHandler
- Defined in:
- lib/errors/logging_error_handler/logging_error_handler.rb
Overview
class that handles errors when message broker can’t be reached, etc…
Instance Method Summary collapse
- #delete_unpublished_log(msg) ⇒ Object
- #fetch_unpublished_logs ⇒ Object
- #handle_error(error, log = nil) ⇒ Object
-
#initialize(fallback_name = nil, config = {}) ⇒ LoggingErrorHandler
constructor
A new instance of LoggingErrorHandler.
Constructor Details
#initialize(fallback_name = nil, config = {}) ⇒ LoggingErrorHandler
Returns a new instance of LoggingErrorHandler.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/errors/logging_error_handler/logging_error_handler.rb', line 8 def initialize(fallback_name = nil, config = {}) return if ChiliLogger.instance.deactivated @default = ChiliLogger::Values::Default.new config ||= {} validate_config(config) fallback_name ||= @default.fallback_broker fallback_broker_class = supported_fallback_brokers[fallback_name.to_sym] unsupported_fallback_broker_error unless fallback_broker_class @fallback_broker = fallback_broker_class.new(config) end |
Instance Method Details
#delete_unpublished_log(msg) ⇒ Object
39 40 41 |
# File 'lib/errors/logging_error_handler/logging_error_handler.rb', line 39 def delete_unpublished_log(msg) @fallback_broker.(msg) end |
#fetch_unpublished_logs ⇒ Object
35 36 37 |
# File 'lib/errors/logging_error_handler/logging_error_handler.rb', line 35 def fetch_unpublished_logs @fallback_broker. end |
#handle_error(error, log = nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/errors/logging_error_handler/logging_error_handler.rb', line 22 def handle_error(error, log = nil) return if ChiliLogger.instance.deactivated = (error, log) @fallback_broker.publish() rescue StandardError => e puts 'There was a problem with both the Message Broker and the Fallback Broker simultaneously. To keep the application running and prevent downtime, ChiliLogger will ignore this errors and discard the log it was currently trying to publish. Please note that logs are being permanently lost.' puts e end |