Skip to content

Commit

Permalink
update logger params
Browse files Browse the repository at this point in the history
  • Loading branch information
AlyaGomaa committed Aug 5, 2024
1 parent 079e025 commit 054bc84
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
6 changes: 4 additions & 2 deletions abstracts/comparison_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ def init(self, **kwargs):
"""


def log(self, green_txt, normal_txt, log_to_results_file=True, end="\n"):
def log(self, colored_txt, normal_txt, log_to_results_file=True,
end="\n", error=False):
"""
gives the txt to the logger to log it to stdout and results.txt
"""
self.notify_observers((normal_txt, green_txt, log_to_results_file, end))
self.notify_observers(
(normal_txt, colored_txt, log_to_results_file, end, error))


def __del__(self):
Expand Down
8 changes: 6 additions & 2 deletions abstracts/dbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ def __init__(
self.connect()
self.init()

def log(self, green_txt, normal_txt, log_to_results_file=True, end="\n"):
def log(self, colored_txt, normal_txt, log_to_results_file=True,
end="\n",
error=False):
"""
gives the txt to the logger to log it to stdout and results.txt
"""
self.notify_observers((normal_txt, green_txt, log_to_results_file, end))
self.notify_observers((
normal_txt, colored_txt, log_to_results_file, end, error
))


def connect(self):
Expand Down
9 changes: 6 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def setup_output_dir(self):
return output_dir


def log(self, green_txt, normal_txt, log_to_results_file=True,
def log(self, colored_txt, normal_txt, log_to_results_file=True,
end="\n", error=False):
self.notify_observers(
(normal_txt, green_txt, log_to_results_file, end, error)
(normal_txt, colored_txt, log_to_results_file, end, error)
)


Expand All @@ -117,7 +117,7 @@ def print_stats(self, print_stats_event):
now = current_datetime.strftime('%Y-%m-%d %H:%M:%S')
to_print = f"{now} - Total parsed flows by "
for tool in self.supported_tools:
to_print += f"{tool}: {self.db.get_flows_parsed('slips')}"
to_print += f"{tool}: {self.db.get_flows_parsed('slips')} "
print(to_print, end='\r')

def get_human_readable_datetime(self) -> str:
Expand Down Expand Up @@ -235,6 +235,9 @@ def main(self):

all_good: bool = tools_parser.start_parsers()
if not all_good:
self.log("",
"Problem occurred with parsers. Stopping.",
error=True)
return

# now that the parsers ended don't print more stats
Expand Down
8 changes: 6 additions & 2 deletions metrics/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ def __init__(
self.tool = tool


def log(self, green_txt, normal_txt, log_to_results_file=True, end="\n"):
self.notify_observers((normal_txt, green_txt, log_to_results_file, end))
def log(self, colored_txt, normal_txt, log_to_results_file=True,
end="\n",
error=False):
self.notify_observers((
normal_txt, colored_txt, log_to_results_file, end, error
))

def confusion_matrix(self, labels: Iterator):
"""
Expand Down
2 changes: 1 addition & 1 deletion parsers/suricata.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def parse(self):
if 'malicious' in label.lower():
self.label_tw(timestamp, line['src_ip'], 'malicious')

self.print_stats()
self.print_stats()
os._exit(0)
except Exception as e:
self.log("An error occurred: ", e, error=True)
Expand Down

0 comments on commit 054bc84

Please sign in to comment.