Skip to content

Commit

Permalink
Improving analyzers' report format (#72)
Browse files Browse the repository at this point in the history
* improving report format of format analyzer

* improving report format of startup header analyzer
  • Loading branch information
kitrady authored Jul 28, 2024
1 parent 60c614d commit 2ce535e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/alogamous/format_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@ def read_log_line(self, line):
self.startup_block = False

def report(self, out_stream):
out_stream.write("\nLines that do not conform to log format:\n- ")
out_stream.write("\n- ".join(self.un_formated_lines))
if self.un_formated_lines:
out_stream.write("\nLines that do not conform to log format:\n- ")
out_stream.write("\n- ".join(self.un_formated_lines))
else:
out_stream.write("All lines conform to log line format")
2 changes: 1 addition & 1 deletion src/alogamous/startup_header_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ def read_log_line(self, line):
self.startup_block = False

def report(self, out_stream):
out_stream.write("\nLines that are part of the startup header:\n- ")
out_stream.write("\nLines that are part of the startup header(s):\n- ")
out_stream.write("\n- ".join(self.startup_lines))
24 changes: 23 additions & 1 deletion tests/format_analyzer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from alogamous import format_analyzer, log_line_parser


def test_format_analyzer():
def test_format_analyzer_with_bad_lines():
parser = log_line_parser.LogLineParser(
["datetime", "source", "level", "message"], " - ", "===================================================="
)
Expand Down Expand Up @@ -31,3 +31,25 @@ def test_format_analyzer():
- Hello I am a bad log line
- Hello I am a bad log line"""
)


def test_format_analyzer_with_good_lines():
parser = log_line_parser.LogLineParser(
["datetime", "source", "level", "message"], " - ", "===================================================="
)
format_checker = format_analyzer.FormatAnalyzer(parser)
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
2024-06-20 11:00:18,116 - root - INFO - prometheus client http server running"""
out_stream = StringIO()
for line in in_stream.splitlines():
format_checker.read_log_line(line)
format_checker.report(out_stream)
assert out_stream.getvalue() == "All lines conform to log line format"
2 changes: 1 addition & 1 deletion tests/startup_header_analyzer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_report():
assert (
out_stream.getvalue()
== """
Lines that are part of the startup header:
Lines that are part of the startup header(s):
- STARTING Tracking service
- Start time: 2024-06-20 09:00:00.001550+00:00
- Version: 2729a
Expand Down

0 comments on commit 2ce535e

Please sign in to comment.