-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added parser that turns log line strings into dictionaries * adding constant strings to avoid typo errors * adding analyzer to parse startup header --------- Co-authored-by: krady <[email protected]>
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from alogamous import analyzer, log_line_parser | ||
|
||
parser = log_line_parser.LogLineParser( | ||
"====================================================", ["datetime", "source", "level", "message"], " - " | ||
) | ||
|
||
|
||
class StartupHeaderAnalyzer(analyzer.Analyzer): | ||
def __init__(self): | ||
self.startup_block = False | ||
self.startup_lines = [] | ||
|
||
def read_log_line(self, line): | ||
line_type = parser.parse(line)["type"] | ||
if self.startup_block is False and line_type == log_line_parser.LineType.HEADER_LINE: | ||
self.startup_block = True | ||
elif self.startup_block is True: | ||
if line_type == log_line_parser.LineType.UNSTRUCTURED_LINE: | ||
self.startup_lines.append(line) | ||
elif line_type == log_line_parser.LineType.HEADER_LINE: | ||
self.startup_block = False | ||
|
||
def report(self, out_stream): | ||
out_stream.write("\n".join(self.startup_lines)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import io | ||
|
||
from alogamous import startup_header_analyzer | ||
|
||
|
||
def test_report(): | ||
startup_analyzer = startup_header_analyzer.StartupHeaderAnalyzer() | ||
in_stream = """ | ||
==================================================== | ||
STARTING Tracking service | ||
Start time: 2024-06-20 09:00:00.001550+00:00 | ||
Version: 2729a | ||
Command line: ['.venv/bin/python3', '-m', 'app.tracking_service', '--market', 'US', '--version', '2729a'] | ||
==================================================== | ||
2024-06-20 11:00:17,983 - root - INFO - Adding subscription for pid None | ||
2024-06-20 11:00:18,115 - root - INFO - Initialized Influx DB Client to host | ||
2024-06-20 11:00:18,115 - root - INFO - Scheduling Error Handler in 150.0 seconds | ||
""" | ||
out_stream = io.StringIO() | ||
for line in in_stream.splitlines(): | ||
startup_analyzer.read_log_line(line) | ||
startup_analyzer.report(out_stream) | ||
assert ( | ||
out_stream.getvalue() | ||
== """STARTING Tracking service | ||
Start time: 2024-06-20 09:00:00.001550+00:00 | ||
Version: 2729a | ||
Command line: ['.venv/bin/python3', '-m', 'app.tracking_service', '--market', 'US', '--version', '2729a']""" | ||
) |