From ed383d9528bd677ea001453a6a2da9a4c8db7dcc Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Fri, 8 Mar 2024 13:30:32 +0000 Subject: [PATCH 1/2] (#368) Reduce debug log amount --- src/dodal/log.py | 11 ++++++++--- tests/unit_tests/test_log.py | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/dodal/log.py b/src/dodal/log.py index c59c735738..7484875095 100644 --- a/src/dodal/log.py +++ b/src/dodal/log.py @@ -18,8 +18,9 @@ DEFAULT_FORMATTER = logging.Formatter( "[%(asctime)s] %(name)s %(module)s %(levelname)s: %(message)s" ) -ERROR_LOG_BUFFER_LINES = 200000 +ERROR_LOG_BUFFER_LINES = 20000 INFO_LOG_DAYS = 30 +DEBUG_LOG_DAYS = 7 class CircularMemoryHandler(logging.Handler): @@ -131,10 +132,14 @@ def set_up_DEBUG_memory_handler( print(f"Logging to {path/filename}") debug_path = path / "debug" debug_path.mkdir(parents=True, exist_ok=True) - file_handler = TimedRotatingFileHandler(filename=debug_path / filename, when="H") + file_handler = TimedRotatingFileHandler( + filename=debug_path / filename, when="H", backupCount=DEBUG_LOG_DAYS + ) file_handler.setLevel(logging.DEBUG) memory_handler = CircularMemoryHandler( - capacity=capacity, flushLevel=logging.ERROR, target=file_handler + capacity=capacity, + flushLevel=logging.ERROR, + target=file_handler, ) memory_handler.setLevel(logging.DEBUG) memory_handler.addFilter(beamline_filter) diff --git a/tests/unit_tests/test_log.py b/tests/unit_tests/test_log.py index 410618f605..d0ed3205f6 100644 --- a/tests/unit_tests/test_log.py +++ b/tests/unit_tests/test_log.py @@ -91,7 +91,7 @@ def test_no_env_variable_sets_correct_file_handler( expected_calls = [ call(filename=PosixPath("tmp/dev/dodal.log"), when="MIDNIGHT", backupCount=30), - call(PosixPath("tmp/dev/debug/dodal.log"), when="H"), + call(PosixPath("tmp/dev/debug/dodal.log"), when="H", backupCount=7), ] mock_file_handler.assert_has_calls(expected_calls, any_order=True) From 5bd571f10039241838989556ab1cc32a391fbe80 Mon Sep 17 00:00:00 2001 From: Dominic Oram Date: Fri, 8 Mar 2024 13:51:01 +0000 Subject: [PATCH 2/2] (#368) Be clearer with constant name --- src/dodal/log.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dodal/log.py b/src/dodal/log.py index 7484875095..ad7083181c 100644 --- a/src/dodal/log.py +++ b/src/dodal/log.py @@ -20,7 +20,7 @@ ) ERROR_LOG_BUFFER_LINES = 20000 INFO_LOG_DAYS = 30 -DEBUG_LOG_DAYS = 7 +DEBUG_LOG_FILES_TO_KEEP = 7 class CircularMemoryHandler(logging.Handler): @@ -133,7 +133,7 @@ def set_up_DEBUG_memory_handler( debug_path = path / "debug" debug_path.mkdir(parents=True, exist_ok=True) file_handler = TimedRotatingFileHandler( - filename=debug_path / filename, when="H", backupCount=DEBUG_LOG_DAYS + filename=debug_path / filename, when="H", backupCount=DEBUG_LOG_FILES_TO_KEEP ) file_handler.setLevel(logging.DEBUG) memory_handler = CircularMemoryHandler(