Island: Modify function get_log_file() -> get_log_file_path()
This commit is contained in:
parent
988f393a20
commit
8da12a7970
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue