Sha256: 39a5bfebf1f2a8e7e9051a0afbf9824e8ca458293201e3f8d41e90938624f610

Contents?: true

Size: 1.41 KB

Versions: 12

Compression:

Stored size: 1.41 KB

Contents

# Text Log Formatter
module DispatchRider
  module Logging
    class TextFormatter

      def format(data)
        case data[:phase]
        when :complete
          "Completed execution of: #{message_info_fragment(data)} in #{format_duration(data[:duration])} seconds"
        when :fail
          "Failed execution of: #{exception_info_fragment(data)}"
        when :start
          "Starting execution of: #{message_info_fragment(data)}"
        when :success
          "Succeeded execution of: #{message_info_fragment(data)}"
        when :stop
          "Got stop #{data[:reason] ? '(' + data[:reason] + ')' : '' } while executing: #{message_info_fragment(data)}"
        when :error_handler_fail
          "Failed error handling of: #{exception_info_fragment(data)}"
        else
          raise ArgumentError, "Invalid phase : #{data[:phase].inspect}"
        end
      end

      private

      def message_info_fragment(data)
        "(#{data[:guid]}): #{data[:subject]} : #{message_info_arguments(data[:body]).inspect}"
      end

      def exception_info_fragment(data)
        "(#{data[:guid]}): #{data[:subject]} with #{data[:exception][:class]}: #{data[:exception][:message]}"
      end

      def message_info_arguments(body)
        body.dup.tap do |m|
          m.delete('guid')
          m.delete('object_id')
        end
      end

      def format_duration(duration)
        '%.2f' % [duration]
      end

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
dispatch-rider-1.9.0 lib/dispatch-rider/logging/text_formatter.rb
dispatch-rider-1.8.6 lib/dispatch-rider/logging/text_formatter.rb
dispatch-rider-1.8.5 lib/dispatch-rider/logging/text_formatter.rb
dispatch-rider-1.8.4 lib/dispatch-rider/logging/text_formatter.rb
dispatch-rider-1.8.3 lib/dispatch-rider/logging/text_formatter.rb
dispatch-rider-1.8.2 lib/dispatch-rider/logging/text_formatter.rb
dispatch-rider-1.8.1 lib/dispatch-rider/logging/text_formatter.rb
dispatch-rider-1.8.0 lib/dispatch-rider/logging/text_formatter.rb
dispatch-rider-1.7.2 lib/dispatch-rider/logging/text_formatter.rb
dispatch-rider-1.7.1 lib/dispatch-rider/logging/text_formatter.rb
dispatch-rider-1.7.0 lib/dispatch-rider/logging/text_formatter.rb
dispatch-rider-1.6.2 lib/dispatch-rider/logging/text_formatter.rb