From 5e78666f91cebebc9e0ff9f6462d78107234ecce Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 2 Jun 2021 08:40:49 -0400 Subject: [PATCH] island: Add function to setup default failsafe logger --- .../monkey_island/cc/server_utils/island_logger.py | 9 +++++++++ .../cc/server_utils/test_island_logger.py | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/monkey/monkey_island/cc/server_utils/island_logger.py b/monkey/monkey_island/cc/server_utils/island_logger.py index 9a8929e3a..06547d84d 100644 --- a/monkey/monkey_island/cc/server_utils/island_logger.py +++ b/monkey/monkey_island/cc/server_utils/island_logger.py @@ -30,6 +30,15 @@ def setup_logging(data_dir_path, log_level): _add_console_handler(logger, formatter) +def setup_default_failsafe_logging(): + logger = logging.getLogger() + logger.setLevel(logging.DEBUG) + + formatter = _get_log_formatter() + + _add_console_handler(logger, formatter) + + def _get_log_formatter(): return logging.Formatter(LOG_FORMAT) diff --git a/monkey/tests/unit_tests/monkey_island/cc/server_utils/test_island_logger.py b/monkey/tests/unit_tests/monkey_island/cc/server_utils/test_island_logger.py index 6061109d1..c4256252f 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/server_utils/test_island_logger.py +++ b/monkey/tests/unit_tests/monkey_island/cc/server_utils/test_island_logger.py @@ -87,3 +87,15 @@ def test_setup_logging_console_log_level_lower_case(capsys, tmpdir): captured = capsys.readouterr() assert TEST_STRING in captured.out + + +def test_setup_defailt_failsafe_logging(capsys): + TEST_STRING = "Hello, Monkey! (Console; Log level: debug)" + + island_logger.setup_default_failsafe_logging() + logger = logging.getLogger("TestLogger") + logger.debug(TEST_STRING) + + captured = capsys.readouterr() + assert TEST_STRING in captured.out + assert "DEBUG" in captured.out