Sha256: 58f65145730cfef37ad39074dfc1df87fb403c0f4c1d8fea5910bbd448b56d33

Contents?: true

Size: 844 Bytes

Versions: 9

Compression:

Stored size: 844 Bytes

Contents

# frozen_string_literal: true

module Kiev
  module RequestLogger
    module Mixin
      NEW_LINE = "\n"
      LOG_ERROR = "ERROR"

      def wrap_request_logger(event, **data, &_block)
        began_at = Time.now
        error = nil

        begin
          return_value = yield
        rescue StandardError => e
          error = e
        end

        begin
          data[:request_duration] = ((Time.now - began_at) * 1000).round(3)
          if error
            data[:error_class] = error.class.name
            data[:error_message] = error.message[0..5000]
            data[:error_backtrace] = Array(error.backtrace).join(NEW_LINE)[0..5000]
            data[:level] = LOG_ERROR
          end

          Kiev.event(event, data)
        ensure
          raise error if error

          return_value
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
kiev-4.9.0 lib/kiev/request_logger.rb
kiev-4.8.3 lib/kiev/request_logger.rb
kiev-4.8.2 lib/kiev/request_logger.rb
kiev-4.8.1 lib/kiev/request_logger.rb
kiev-4.8.0 lib/kiev/request_logger.rb
kiev-4.7.0 lib/kiev/request_logger.rb
kiev-4.6.0 lib/kiev/request_logger.rb
kiev-4.5.0 lib/kiev/request_logger.rb
kiev-4.4.0 lib/kiev/request_logger.rb