Python rolling log to a variable
<p>I have an application that makes use of multi-threading and is run in the background on a server. In order to monitor the application without having to log on to the server, I decided to include <a href="http://bottlepy.org" rel="noreferrer">Bottle</a> in order to respond to a few HTTP endpoints and report status, perform remote shutdown, etc.</p>

<p>I also wanted to add a way to consult the logfile. I could log using the <code>FileHandler</code> and send the destination file when the URL is requested (e.g. <code>/log</code>).</p>

<p>However, I was wondering if it'd be possible to implement something like a <code>RotatingFileHandler</code>, but instead of logging to a file, logging to a variable (e.g. <code>BytesIO</code>). This way, I could limit the log to the most recent information, while at the same time being able to return it to the browser as text instead of as a separate file download.</p>

<p>The <code>RotatingFileHandler</code> requires a filename, so it's not an option to pass it a <code>BytesIO</code> stream. Logging to a variable itself is perfectly doable (e.g. <a href="http://alanwsmith.com/capturing-python-log-output-in-a-variable" rel="noreferrer">Capturing Python Log Output In A Variable</a>), but I'm a bit stumped on how to do the <em>rolling</em> part.</p>

<p>Any thoughts, hints, suggestions would be greatly appreciated.</p>