Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding warning analyzer #50

Merged
merged 7 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/alogamous/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from alogamous import analyzer, directory_reader, echo_analyzer, error_counter_analyzer, line_count_analyzer
from alogamous import (
analyzer,
directory_reader,
echo_analyzer,
error_counter_analyzer,
line_count_analyzer,
warning_analyzer,
)

with open("../../data/test_output_file.txt", "a") as output_file:
reader = directory_reader.DirectoryReader("../../data")
Expand All @@ -7,6 +14,7 @@
echo_analyzer.EchoAnalyzer(),
error_counter_analyzer.ErrorCounterAnalyzer(),
line_count_analyzer.LineCountAnalyzer(),
warning_analyzer.WarningAnalyzer(),
],
reader.read(),
output_file,
Expand Down
20 changes: 20 additions & 0 deletions src/alogamous/warning_analyzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from alogamous import analyzer


class WarningAnalyzer(analyzer.Analyzer):
def __init__(self):
self.count = 0

def read_log_line(self, line):
line_list = line.split(" ")
# List should have format [date, timestamp, -, root, -, log message type, -, first word of message...]
if line_list[5].lower() == "warning":
self.count += 1

def report(self, out_stream):
if self.count == 0:
out_stream.write("\n" + "No Warnings were detected.")
elif self.count == 1:
out_stream.write("\n" + "1 Warning was detected.")
else:
out_stream.write("\n" + str(self.count) + " Warnings were detected.")
17 changes: 17 additions & 0 deletions tests/warning_analyzer_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import io

from alogamous import analyzer, warning_analyzer


def test_warning_count():
in_stream = io.StringIO("""2024-06-20 11:00:18,185 - root - INFO - Kafka reading from start of day 2024-06-20 05:00:00+00:00 on topic internal from kafka.servers:9092
2024-06-20 11:00:19,328 - root - INFO - Kafka source starting for topic internal at current offset 7924032 end offset 7928950 on servers kafka.servers:9092
2024-06-20 11:00:22,329 - root - INFO - Kafka topic internal is caught up at offset 7928949
2024-06-20 11:00:22,329 - root - INFO - setting influx write rate to pre-market hours frequency
2024-06-20 11:00:22,329 - root - INFO - Tracking service is caught up
2024-06-20 11:40:43,527 - root - WARNING - instrument not found for sedol BYP321337
2024-06-20 11:40:43,527 - root - WARNING - instrument not found for sedol BYP321337
2024-06-20 17:25:08,029 - root - ERROR - Exception in message handler <bound method TrackingService.method of <app.tracking_service.TrackingService object at 0x7feba0d0>> TrackingService.on_order_change() missing 1 required positional argument: 'order_identifier'""")
out_stream = io.StringIO()
analyzer.analyze_log_stream([warning_analyzer.WarningAnalyzer()], in_stream, out_stream)
assert out_stream.getvalue() == "\n2 Warnings were detected."
Loading