lib/dispatch-rider/logging/lifecycle_logger.rb in dispatch-rider-1.6.1 vs lib/dispatch-rider/logging/lifecycle_logger.rb in dispatch-rider-1.6.2
- old
+ new
@@ -1,15 +1,15 @@
module DispatchRider
module Logging
class LifecycleLogger
class << self
def log_error_handler_fail(message, exception)
- logger.error formatter.format_error_handler_fail(message, exception)
+ new(:error_handler_fail, message, exception: exception).log
end
def log_got_stop(reason, message)
- logger.info formatter.format_got_stop(message, reason)
+ new(:stop, message, reason: reason).log
end
def wrap_handling(message)
start_time = Time.now
log_start(message)
@@ -23,31 +23,73 @@
end
private
def log_complete(message, duration)
- logger.info formatter.format_handling :complete, message, duration: duration
+ new(:complete, message, duration: duration).log
end
def log_fail(message, exception)
- logger.error formatter.format_handling :fail, message, exception: exception
+ new(:fail, message, exception: exception).log
end
def log_success(message)
- logger.info formatter.format_handling :success, message
+ new(:success, message).log
end
def log_start(message)
- logger.info formatter.format_handling :start, message
+ new(:start, message).log
end
+ end
- def formatter
- DispatchRider.config.log_formatter
- end
+ def initialize(kind, message, options = {})
+ @kind = kind
+ @message = message
+ @options = options
+ end
- def logger
- DispatchRider.config.logger
+ def log
+ logger.send(log_action, formatted_data)
+ end
+
+ private
+
+ attr_reader :kind, :message, :options
+
+ def formatter
+ DispatchRider.config.log_formatter
+ end
+
+ def logger
+ DispatchRider.config.logger
+ end
+
+ def additional_info_injector
+ DispatchRider.config.additional_info_injector
+ end
+
+ def translator
+ Translator
+ end
+
+ def translated_message
+ translator.translate(message, kind, options)
+ end
+
+ def interjected_message
+ additional_info_injector.call(translated_message)
+ end
+
+ def formatted_data
+ formatter.format(interjected_message)
+ end
+
+ def log_action
+ case kind
+ when :fail, :error_handler_fail then :error
+ when :start, :stop, :complete, :success then :info
end
end
+
end
end
end