forked from p15670423/monkey
Island: Move get_log_file_contents() from IslandLog to cc/server_utils/island_logger.py
This commit is contained in:
parent
1d11dd227e
commit
7967974c9d
|
@ -3,6 +3,7 @@ from pathlib import Path
|
|||
|
||||
from monkey_island.cc.resources.AbstractResource import AbstractResource
|
||||
from monkey_island.cc.resources.request_authentication import jwt_required
|
||||
from monkey_island.cc.server_utils.island_logger import get_log_file_contents
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -16,11 +17,6 @@ class IslandLog(AbstractResource):
|
|||
@jwt_required
|
||||
def get(self):
|
||||
try:
|
||||
return self._get_log_file_contents()
|
||||
return {"log_file": get_log_file_contents(self._island_log_file_path)}
|
||||
except Exception:
|
||||
logger.error("Monkey Island logs failed to download", exc_info=True)
|
||||
|
||||
def _get_log_file_contents(self):
|
||||
with open(self._island_log_file_path, "rt") as f:
|
||||
log_file = f.read()
|
||||
return {"log_file": log_file}
|
||||
|
|
|
@ -2,6 +2,7 @@ import logging
|
|||
import logging.handlers
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Mapping
|
||||
|
||||
ISLAND_LOG_FILENAME = "monkey_island.log"
|
||||
LOG_FORMAT = "%(asctime)s - %(levelname)s - %(filename)s:%(lineno)s - %(funcName)s() - %(message)s"
|
||||
|
@ -33,6 +34,12 @@ def get_log_file_path(data_dir: Path) -> Path:
|
|||
return data_dir / ISLAND_LOG_FILENAME
|
||||
|
||||
|
||||
def get_log_file_contents(log_file_path: Path) -> Mapping:
|
||||
with open(log_file_path, "rt") as f:
|
||||
log_file = f.read()
|
||||
return log_file
|
||||
|
||||
|
||||
def setup_default_failsafe_logging():
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.DEBUG)
|
||||
|
|
Loading…
Reference in New Issue