Sha256: 6f45178e296770fcdb263036dd5cc645c86c77ef011be971436809bebd092618

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

module DispatchRider
  module Logging
    class LifecycleLogger
      class << self
        def log_error_handler_fail(message, exception)
          logger.error formatter.format_error_handler_fail(message, exception)
        end

        def log_got_stop(reason, message)
          logger.info formatter.format_got_stop(message, reason)
        end

        def wrap_handling(message)
          log_start(message)
          start_time = Time.now
          yield
          log_success(message)
        rescue => exception
          log_fail(message, exception)
          raise exception
        ensure
          log_complete(message, Time.now - start_time)
        end

        private

        def log_complete(message, duration)
          logger.info formatter.format_handling :complete, message, duration: duration
        end

        def log_fail(message, exception)
          logger.error formatter.format_handling :fail, message, exception: exception
        end

        def log_success(message)
          logger.info formatter.format_handling :success, message
        end

        def log_start(message)
          logger.info formatter.format_handling :start, message
        end

        def formatter
          DispatchRider.config.log_formatter
        end

        def logger
          DispatchRider.config.logger
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dispatch-rider-1.6.0 lib/dispatch-rider/logging/lifecycle_logger.rb