Skip to content

Commit

Permalink
Adding warning analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
kschmader committed Jul 12, 2024
1 parent 4a71954 commit 8a748c0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/alogamous/__main__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from alogamous import analyzer, echo_analyzer, error_counter_analyzer, line_count_analyzer
from src.alogamous import analyzer, echo_analyzer, error_counter_analyzer, line_count_analyzer, warning_analyzer

with open("../../data/ex_log_01.txt") as log_file, open("../../data/test_output_file.txt", "a") as output_file:
analyzer.analyze_log_stream(
[
echo_analyzer.EchoAnalyzer(),
error_counter_analyzer.ErrorCounterAnalyzer(),
line_count_analyzer.LineCountAnalyzer(),
warning_analyzer.WarningAnalyzer(),
],
log_file,
output_file,
Expand Down
21 changes: 21 additions & 0 deletions src/alogamous/warning_analyzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from src.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.")
20 changes: 20 additions & 0 deletions tests/warning_analyzer_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import io

from src.alogamous import analyzer, warning_analyzer
import data

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."
)

0 comments on commit 8a748c0

Please sign in to comment.