Class: GitlabQuality::TestTooling::SystemLogs::Finders::JsonLogFinder
- Inherits:
-
Object
- Object
- GitlabQuality::TestTooling::SystemLogs::Finders::JsonLogFinder
show all
- Defined in:
- lib/gitlab_quality/test_tooling/system_logs/finders/json_log_finder.rb
Instance Method Summary
collapse
Constructor Details
#initialize(base_path, file_path) ⇒ JsonLogFinder
10
11
12
13
|
# File 'lib/gitlab_quality/test_tooling/system_logs/finders/json_log_finder.rb', line 10
def initialize(base_path, file_path)
@base_path = base_path
@file_path = file_path
end
|
Instance Method Details
#find(correlation_id) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/gitlab_quality/test_tooling/system_logs/finders/json_log_finder.rb', line 15
def find(correlation_id)
log_file_path = "#{@base_path}/#{@file_path}"
logs = []
if File.exist?(log_file_path) && !correlation_id.nil?
File.foreach(log_file_path) do |line|
begin
json_line = JSON.parse(line, symbolize_names: true)
rescue JSON::ParserError
Runtime::Logger.debug("JsonLogFinder#find attempted to parse invalid JSON: #{line}")
next
end
if (json_line[:correlation_id])&.casecmp?(correlation_id)
normalized_line = normalize_keys(json_line)
logs << new_log(normalized_line)
end
end
end
logs
end
|
#new_log(_data) ⇒ Object
39
40
41
|
# File 'lib/gitlab_quality/test_tooling/system_logs/finders/json_log_finder.rb', line 39
def new_log(_data)
raise 'abstract method new_log must be defined!'
end
|