1

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.

2
  • 1
    can you include more information, such as a sample of the test case code? Commented 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. Commented Aug 27, 2021 at 3:08

2 Answers 2

2

doRollover() will do an immediate rollover.

Sign up to request clarification or add additional context in comments.

1 Comment

this is the correct answer; .rotate() is eventually called by .doRollover() (and not useful by itself without a source and destination)
1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.