Skip to content

Commit

Permalink
Adding warning analyzer (#50)
Browse files Browse the repository at this point in the history
* Adding warning analyzer

* Fixing formatting

* Fixing formatting frfr
:x

* Fixing formatting yet again because @lassour keeps messing it up.

* Finally actually fixing it

---------

Co-authored-by: kschmader <[email protected]>
  • Loading branch information
Rovis27 and kschmader authored Jul 19, 2024
1 parent 3a7276a commit 6a39a70
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
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."

0 comments on commit 6a39a70

Please sign in to comment.