This question is regarding Python logging.handlers.RotatingFileHandler object. The RotatingFileHandler object rotates a file after it fills upto maxBytes(if specified). But wondering if there is a way to force rotation before the log file is filled up. The reason for this is that the test script likes to rotate log files after every iteration of a test case.
- 1can you include more information, such as a sample of the test case code?ti7– ti72021-08-27 03:07:59 +00:00Commented Aug 27, 2021 at 3:07
- What is the timing or criteria for when to force the rotation? There is a solution here that forces rotation on each application start: stackoverflow.com/questions/4654915/…. Maybe you can adapt it on your case.Gino Mempin– Gino Mempin2021-08-27 03:08:00 +00:00Commented Aug 27, 2021 at 3:08
Add a comment |
2 Answers
doRollover() will do an immediate rollover.
1 Comment
ti7
this is the correct answer;
.rotate() is eventually called by .doRollover() (and not useful by itself without a source and destination)You should be able to call .rotate() on the log handler to force rotation
docs https://docs.python.org/3/library/logging.handlers.html#logging.handlers.BaseRotatingHandler.rotate