Class: RailsLogParser::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_log_parser/line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parser, line) ⇒ Line

Returns a new instance of Line.



6
7
8
9
10
11
# File 'lib/rails_log_parser/line.rb', line 6

def initialize(parser, line)
  @parser = parser
  @line = line.strip

  parse
end

Instance Attribute Details

#lineObject (readonly)

Returns the value of attribute line.



4
5
6
# File 'lib/rails_log_parser/line.rb', line 4

def line
  @line
end

#parserObject (readonly)

Returns the value of attribute parser.



4
5
6
# File 'lib/rails_log_parser/line.rb', line 4

def parser
  @parser
end

Instance Method Details

#parseObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/rails_log_parser/line.rb', line 13

def parse
  return if line.empty?

  # empty log line
  match = line.match(/
    \A(?<severity_id>[DIWEFU]),\s                 # I,
    \[(?<datetime>[^\]]+)\s\#(?<pid>\d+)\]\s+     # [2021-11-26T13:11:01.255168 #10158]
    (?<severity_label>[A-Z]+)\s+--\s+[^:]*:\s+    # INFO -- :
    \[(?<id>[a-f0-9\-]{36})\]\s*                  # [b42b65ab-7985-4bc2-a5b5-1fb23e6ad940]
    \z/x)
  if match
    parser.empty_line(match)
    return
  end

  # normal log line
  match = line.match(/
    \A(?<severity_id>[DIWEFU]),\s                 # I,
    \[(?<datetime>[^\]]+)\s\#(?<pid>\d+)\]\s+     # [2021-11-26T13:11:01.255168 #10158]
    (?<severity_label>[A-Z]+)\s+--\s+[^:]*:\s+    # INFO -- :
    \[(?<id>[a-f0-9\-]{36})\]\s                   # [b42b65ab-7985-4bc2-a5b5-1fb23e6ad940]
    (?<message>.*)                                # Processing by Public::Controller
    \z/x)
  if match
    parser.request(match)
    return
  end

  match = line.match(/
    \A(?<severity_id>[DIWEFU]),\s                 # I,
    \[(?<datetime>[^\]]+)\s\#(?<pid>\d+)\]\s+     # [2021-11-26T13:11:01.255168 #10158]
    (?<severity_label>[A-Z]+)\s+--\s+[^:]*:\s+    # INFO -- :
    \[ActiveJob\]                                 # [ActiveJob]
    (?:\s\[[^\]]+\])?                             # [ActionMailer::Parameterized::DeliveryJob]
    \s\[(?<id>[^\]]+)\]\s                         # [09f4c08a-b92e-42e3-9046-7effcf87aa2f]
    (?<message>.*)                                # Performing ActionMailer::Parameterized::DeliveryJob
    \z/x)
  if match
    parser.active_job(match)
    return
  end

  match = line.match(/
    \A(?<severity_id>[DIWEFU]),\s                 # I,
    \[(?<datetime>[^\]]+)\s\#(?<pid>\d+)\]\s+     # [2021-11-26T13:11:01.255168 #10158]
    (?<severity_label>[A-Z]+)\s+--\s+[^:]*:\s     # INFO -- :
    (?<datetime2>[^\s]+)\s                        # 2021-11-26T13:51:30+0000:
    \[Worker[^\]]+\]\s                            # [Worker(delayed_job host:production pid:10411)]
    (?<message>.*)                                # Job GeoLocationSearch
    (?<id>\(id=\d+\)\s\([^)]+\))                  # (id=148781) (queue=default)
    (?<message2>.*)                               # RUNNING
    \z/x)
  if match
    parser.delayed_job(match)
    return
  end

  match = line.match(/
    \A(?<severity_id>[DIWEFU]),\s                 # I,
    \[(?<datetime>[^\]]+)\s\#(?<pid>\d+)\]\s+     # [2021-11-26T13:11:01.255168 #10158]
    (?<severity_label>[A-Z]+)\s+--\s+[^:]*:\s     # INFO -- :
    (?<datetime2>[^\s]+)\s                        # 2021-11-26T13:51:30+0000:
    \[Worker[^\]]+\]\s                            # [Worker(delayed_job host:production pid:10411)]
    (?:\d+\sjobs\sprocessed)|(?:Starting\sjob)    # 19 jobs processed
    (?:.*)                                        # at 2.8816
    \z/x)
  return if match

  # Warning or Message without request
  match = line.match(/
    \A(?<severity_id>[DIWEFU]),\s                 # I,
    \[(?<datetime>[^\]]+)\s\#(?<pid>\d+)\]\s+     # [2021-11-26T13:11:01.255168 #10158]
    (?<severity_label>[A-Z]+)\s+--\s+[^:]*:\s     # INFO -- :
    (?<message>.*)                                # Creating scope :for_tipster. Overwriting existing...
    \z/x)
  if match
    parser.without_request(match)
    return
  end

  match = line.match(/
    \A\[(?<id>[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12})\]\s? # [UUID]
    (?<message>.*)
    \z/x)
  if match
    parser.add_message(match)
    return
  end

  if parser.last_action&.error? || parser.last_action&.fatal? || parser.last_action&.active_job?
    parser.last_action.add_stacktrace(line)
    return
  end

  parser.not_parseable_lines.push(line)
end