Skip to content

Commit

Permalink
Merge pull request #369 from DiamondLightSource/368_reduce_debug_log_…
Browse files Browse the repository at this point in the history
…amount

Reduce debug log amount
  • Loading branch information
DominicOram authored Mar 8, 2024
2 parents 4cddb79 + 5bd571f commit 2aaa01f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/dodal/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_FILES_TO_KEEP = 7


class CircularMemoryHandler(logging.Handler):
Expand Down Expand Up @@ -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_FILES_TO_KEEP
)
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)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2aaa01f

Please sign in to comment.