Sha256: 368e7a99c3e9b2e7bb64c97df6bf803ebbea52d0211049290842adbda137102e
Contents?: true
Size: 1.52 KB
Versions: 4
Compression:
Stored size: 1.52 KB
Contents
# frozen_string_literal: true require 'time' require 'securerandom' class RailsLogParser::Action class << self attr_accessor :last end SEVERITIES = %i[debug info warn error fatal].freeze KNOWN_EXCEPTIONS = { 'ActiveRecord::RecordNotFound' => :fatal, 'ActionController::RoutingError' => :fatal, "Can't verify CSRF token authenticity." => :warn, 'ActionController::InvalidAuthenticityToken' => :fatal, 'ActionController::UnfilteredParameters' => :fatal, }.freeze extend Enumerize enumerize :severity, in: SEVERITIES, predicates: true enumerize :type, in: %i[request without_request delayed_job active_job], predicates: true attr_reader :datetime def initialize(type, id) self.type = type @id = id @messages = [] @stacktrace = [] self.class.last = self end def severity=(value) value = value.downcase.to_sym return unless severity.nil? || SEVERITIES.index(severity.to_sym) < SEVERITIES.index(value) super(value) @headline = nil end def known_exception?(key = nil) @messages.any? do |message| KNOWN_EXCEPTIONS.any? { |e, s| message.include?(e) && severity == s && (key.nil? || key == e) } end end def headline @headline.presence || @messages.first end def datetime=(value) @datetime ||= Time.parse(value) end def after?(datetime) @datetime > datetime end def add_message(value) @messages.push(value) @headline = value if @headline.nil? end def add_stacktrace(value) @stacktrace.push(value) end end
Version data entries
4 entries across 4 versions & 1 rubygems