title: Custom Log File That Doesn't Grow Past a Given Size
body: <p>I need to write some output to a log file every time certain events in my application are triggered. Right now I'm doing this in the simplest way imagineable: </p>
  
  <pre><code>with open('file.log', 'a+') as file:
      file.write('some info')
  </code></pre>
  
  <p>This works, but the problem is I don't want the file to grow indefinitely. I want a hard size cutoff of, say 25 MB. But I don't want to simply clear the file when it reaches that size. </p>
  
  <p>Instead, I want it to function how I believe other log files work, clearing the oldest data from the top of the file and appending the new data to the end of the file. What would be a good approach to achieving this in Python? Note that I can't use Python's logging library because this is for a Celery application and (a) I already have logging set up for purposes unrelated to this and (b) Celery and the logging library do not play well together AT ALL. </p>