Source

django-triager-bot / djangotriager / reporter.py

from StringIO import StringIO
import logging

class Reporter(object):
    def __init__(self, name=""):
        self._logger = logging.Logger(name, logging.DEBUG)
        formatter = logging.Formatter("%(name)s - %(levelname)s - %(message)s")
        self._buffer = StringIO()
        handler = logging.StreamHandler(self._buffer)
        handler.setFormatter(formatter)
        self._logger.addHandler(handler)

    def get_buffer(self):
        return self._buffer.getvalue()

    def info(self, message):
        self._logger.info(message)

    def warn(self, message):
        self._logger.warn(message)

    def debug(self, message):
        self._logger.debug(message)