Sha256: ea7b4d7d628b35ff6dc0492a06354aed8b3c10f6c78421bc7215a6fdb938f106

Contents?: true

Size: 712 Bytes

Versions: 1

Compression:

Stored size: 712 Bytes

Contents

module Logifyer
  module Common
    ANSI_ESCAPE_REGEX = /\e\[\d+(;\d+)*m/.freeze
    def msg2str(msg)
      case msg
      when ::String
        clean_msg = remove_ansi_escape_codes(msg)
        clean_msg.gsub("\n", " | ")
      when ::Exception
        "#{remove_ansi_escape_codes(msg.message)} (#{msg.class}) | " <<
        (msg.backtrace || []).map { |line| remove_ansi_escape_codes(line) }.join(" | ")
      else
        remove_ansi_escape_codes(msg.inspect)
      end
    end

    def current_time(time)
      return time if time
      Time.respond_to?(:current) ? Time.current : Time.now
    end

    private

    def remove_ansi_escape_codes(text)
      text.gsub(ANSI_ESCAPE_REGEX, '')
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
logifyer-0.1.0 lib/logifyer/common.rb