From 8da12a7970e8acb741f82abcf79b6dc5e74c8dab Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Mon, 1 Aug 2022 13:24:13 +0530 Subject: [PATCH] Island: Modify function get_log_file() -> get_log_file_path() --- .../cc/server_utils/island_logger.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/monkey/monkey_island/cc/server_utils/island_logger.py b/monkey/monkey_island/cc/server_utils/island_logger.py index c0f55a3aa..cf89c76f7 100644 --- a/monkey/monkey_island/cc/server_utils/island_logger.py +++ b/monkey/monkey_island/cc/server_utils/island_logger.py @@ -2,7 +2,7 @@ import logging import logging.handlers import sys from pathlib import Path -from typing import Mapping +from typing import Optional ISLAND_LOG_FILENAME = "monkey_island.log" LOG_FORMAT = "%(asctime)s - %(levelname)s - %(filename)s:%(lineno)s - %(funcName)s() - %(message)s" @@ -66,14 +66,14 @@ def reset_logger(): logger.removeHandler(handler) -def get_log_file() -> Mapping: +def get_log_file_path() -> Optional[str]: """ - This is a helper function for the Monkey Island log download function. - It finds the logger handlers and checks if one of them is a fileHandler of any kind by - checking if the handler has the property handler.baseFilename. + Finds the log file by finding the logger handlers and checking if one of them is a fileHandler + of any kind by checking if the handler has the property handler.baseFilename. - :return: A dict with log file contents + :return: Log file path """ + logger = logging.getLogger(__name__) logger_handlers = logger.parent.handlers @@ -81,9 +81,7 @@ def get_log_file() -> Mapping: if hasattr(handler, "baseFilename"): logger.info("Log file found: {0}".format(handler.baseFilename)) log_file_path = handler.baseFilename - with open(log_file_path, "rt") as f: - log_file = f.read() - return {"log_file": log_file} + return log_file_path logger.warning("No log file could be found, check logger config.") return None