class EXEL::Middleware::Logging

Middleware to add a prefix to all messages logged during processor execution. The prefix is specified by the :log_prefix key in the context. Also logs start, finish, and failure of the processor execution.

Public Instance Methods

call(processor_class, context, _args, &block) click to toggle source
# File lib/exel/middleware/logging.rb, line 8
def call(processor_class, context, _args, &block)
  EXEL::Logging.with_prefix("#{context[:log_prefix]}[#{processor_class}] ") { log_process(&block) }
end

Private Instance Methods

duration(start_time) click to toggle source
# File lib/exel/middleware/logging.rb, line 25
def duration(start_time)
  (Time.now - start_time).round(3)
end
log_process() { || ... } click to toggle source
# File lib/exel/middleware/logging.rb, line 14
def log_process
  start_time = Time.now

  yield

  EXEL.logger.info "Finished in #{duration(start_time)} seconds"
rescue Exception # rubocop:disable Lint/RescueException
  EXEL.logger.info "Failed in #{duration(start_time)} seconds"
  raise
end