Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Debugging: LogInteractorExecution
# Usage:
#
# class SomeInteractor
# include Interactor
# include LogInteractorExecution
#
# # ...
#
# private
#
# def some_method
# log_method_start(__method__)
# # ...
# log_method_finish(__method__)
# end
# end
#
module LogInteractorExecution
LOG_HANDLE = 'LogInteractorExecution'.freeze
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
def self.included(base)
base.class_eval do
around do |interactor|
log_interactor_start(base)
context.start_time = Time.now
interactor.call
context.finish_time = Time.now
context.time_in_seconds = context.finish_time - context.start_time
log_interactor_finish(base, context)
end
def log_interactor_start(base)
start_message = "#{LOG_HANDLE}: STARTED #{base} -- Started at #{Time.now}"
Rails.logger.info(start_message)
end
def log_interactor_finish(base, context)
finish_message = "#{LOG_HANDLE}: FINISHED #{base} -- Finished in #{context.time_in_seconds} seconds"
Rails.logger.info(finish_message)
end
def log_method_start(method)
Rails.logger.info("#{LOG_HANDLE}: Started ##{method}")
end
def log_method_finish(method)
Rails.logger.info("#{LOG_HANDLE}: Finished ##{method}")
end
end
end
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.