forked from p15670423/monkey
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 logging.handlers
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Mapping
|
from typing import Optional
|
||||||
|
|
||||||
ISLAND_LOG_FILENAME = "monkey_island.log"
|
ISLAND_LOG_FILENAME = "monkey_island.log"
|
||||||
LOG_FORMAT = "%(asctime)s - %(levelname)s - %(filename)s:%(lineno)s - %(funcName)s() - %(message)s"
|
LOG_FORMAT = "%(asctime)s - %(levelname)s - %(filename)s:%(lineno)s - %(funcName)s() - %(message)s"
|
||||||
|
@ -66,14 +66,14 @@ def reset_logger():
|
||||||
logger.removeHandler(handler)
|
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.
|
Finds the log file by finding the logger handlers and checking if one of them is a fileHandler
|
||||||
It finds the logger handlers and checks if one of them is a fileHandler of any kind by
|
of any kind by checking if the handler has the property handler.baseFilename.
|
||||||
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 = logging.getLogger(__name__)
|
||||||
|
|
||||||
logger_handlers = logger.parent.handlers
|
logger_handlers = logger.parent.handlers
|
||||||
|
@ -81,9 +81,7 @@ def get_log_file() -> Mapping:
|
||||||
if hasattr(handler, "baseFilename"):
|
if hasattr(handler, "baseFilename"):
|
||||||
logger.info("Log file found: {0}".format(handler.baseFilename))
|
logger.info("Log file found: {0}".format(handler.baseFilename))
|
||||||
log_file_path = handler.baseFilename
|
log_file_path = handler.baseFilename
|
||||||
with open(log_file_path, "rt") as f:
|
return log_file_path
|
||||||
log_file = f.read()
|
|
||||||
return {"log_file": log_file}
|
|
||||||
|
|
||||||
logger.warning("No log file could be found, check logger config.")
|
logger.warning("No log file could be found, check logger config.")
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Reference in New Issue