How to create a Python or Django logger to log to a string

I had to allow some of our admin users to view the logic and results of a parsing module to help find and pinpoint improvements. Since my backend Python Celery module already uses Python logging, I needed a way to log to a string to display the results on a Web page.

Here’s a function that will return a StringIO variable and a Python logger. Once you are done logging or need the logger results, you can easily get the output logger in a string. Also, I found a Stack Overflow article to remove Django database debug info from being logged so I added this as a default parameter that can be changed.

Here’s the Gist:

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>