forked from p15670423/monkey
Fix unit tests and modify code based on failed tests (tests/monkey_island/cc/server_utils/test_island_logger.py)
This commit is contained in:
parent
f84e4aed2c
commit
6d04e7cbb4
|
@ -36,10 +36,7 @@ LOGGER_CONFIG_DICT = {
|
|||
}
|
||||
|
||||
|
||||
def setup_logging(
|
||||
data_dir_path,
|
||||
log_level,
|
||||
):
|
||||
def setup_logging(data_dir_path, log_level):
|
||||
"""
|
||||
Setup the logging configuration
|
||||
:param data_dir_path: data directory file path
|
||||
|
@ -48,11 +45,16 @@ def setup_logging(
|
|||
"""
|
||||
|
||||
logger_configuration = deepcopy(LOGGER_CONFIG_DICT)
|
||||
logger_configuration["root"]["level"] = log_level
|
||||
|
||||
if not os.path.exists(data_dir_path):
|
||||
os.makedirs(data_dir_path, mode=0o700, exist_ok=True)
|
||||
|
||||
logger_configuration["handlers"]["info_file_handler"]["filename"] = os.path.join(
|
||||
data_dir_path, "monkey_island.log"
|
||||
)
|
||||
logger_configuration["root"]["level"] = log_level
|
||||
_expanduser_log_file_paths(logger_configuration)
|
||||
|
||||
logging.config.dictConfig(logger_configuration)
|
||||
|
||||
|
||||
|
|
|
@ -3,12 +3,7 @@ import os
|
|||
|
||||
import pytest
|
||||
|
||||
from monkey_island.cc.server_utils.island_logger import json_setup_logging
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def test_logger_config_path(resources_dir):
|
||||
return os.path.join(resources_dir, "logger_config.json")
|
||||
from monkey_island.cc.server_utils.island_logger import setup_logging
|
||||
|
||||
|
||||
# TODO move into monkey/monkey_island/cc/test_common/fixtures after rebase/backmerge
|
||||
|
@ -17,11 +12,13 @@ def mock_home_env(monkeypatch, tmpdir):
|
|||
monkeypatch.setenv("HOME", str(tmpdir))
|
||||
|
||||
|
||||
def test_expanduser_filename(mock_home_env, tmpdir, test_logger_config_path):
|
||||
INFO_LOG = os.path.join(tmpdir, "info.log")
|
||||
def test_expanduser_filename(mock_home_env, tmpdir):
|
||||
DATA_DIR = tmpdir
|
||||
INFO_LOG = os.path.join(DATA_DIR, "monkey_island.log")
|
||||
LOG_LEVEL = "DEBUG"
|
||||
TEST_STRING = "Hello, Monkey!"
|
||||
|
||||
json_setup_logging(test_logger_config_path)
|
||||
setup_logging(DATA_DIR, LOG_LEVEL)
|
||||
|
||||
logger = logging.getLogger("TestLogger")
|
||||
logger.info(TEST_STRING)
|
||||
|
|
Loading…
Reference in New Issue