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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
# File 'lib/u3d/log_analyzer.rb', line 77
def parse_line(line)
@lines_memory.push(line).shift
@phases.each do |name, phase|
next if name == @active_phase
next unless line =~ phase['phase_start_pattern']
finish_phase if @active_phase
@active_phase = name
UI.verbose("--- Beginning #{name} phase ---")
break
end
apply_ruleset = lambda do |ruleset, |
if @active_rule && ruleset[@active_rule]
rule = ruleset[@active_rule]
pattern = rule['end_pattern']
if line =~ pattern
unless @rule_lines_buffer.empty?
@rule_lines_buffer.each do |l|
UI.send(rule['type'], "[#{}] " + l)
end
end
if rule['end_message'] != false
if rule['end_message']
match = line.match(pattern)
params = match.names.map(&:to_sym).zip(match.captures).to_h
message = inject(rule['end_message'], params: params)
else
message = line.chomp
end
message = "[#{}] " + message
UI.send(rule['type'], message)
end
@active_rule = nil
@context.clear
@rule_lines_buffer.clear
elsif rule['store_lines']
match = false
rule['ignore_lines']&.each do |pat|
if line =~ pat
match = true
break
end
end
@rule_lines_buffer << line.chomp unless match
end
end
if @active_rule.nil?
ruleset.each do |rn, r|
pattern = r['start_pattern']
next unless line =~ pattern
@active_rule = rn if r['end_pattern']
match = line.match(pattern)
@context = match.names.map(&:to_sym).zip(match.captures).to_h
if r['fetch_line_at_index'] || r['fetch_first_line_not_matching']
if r['fetch_line_at_index']
fetched_line = @lines_memory.reverse[r['fetch_line_at_index']]
else
fetched_line = nil
@lines_memory.reverse.each do |l|
match = false
r['fetch_first_line_not_matching'].each do |pat|
next unless l =~ pat
match = true
break
end
next if match
fetched_line = l
break
end
end
if fetched_line
if r['fetched_line_pattern']
match = fetched_line.match(r['fetched_line_pattern'])
@context.merge!(match.names.map(&:to_sym).zip(match.captures).to_h)
end
if r['fetched_line_message'] != false
message = if r['fetched_line_message']
inject(r['fetched_line_message'])
else
fetched_line.chomp
end
message = "[#{}] " + message
UI.send(r['type'], message)
end
end
end
if r['start_message'] != false
message = if r['start_message']
inject(r['start_message'])
else
line.chomp
end
message = "[#{}] " + message
UI.send(r['type'], message)
end
break
end
end
end
if @active_phase
apply_ruleset.call(@phases[@active_phase]['rules'], @active_phase)
finish_phase if @phases[@active_phase]['phase_end_pattern'] && @phases[@active_phase]['phase_end_pattern'] =~ line
end
apply_ruleset.call(@generic_rules, 'GENERAL')
end
|