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