'Initializes the buffer, which wraps the given stream or sys.stderr.
The state of the LogsBuffer is protected by a separate lock.  The lock is
acquired before any variables are mutated or accessed, and released
afterward.  A recursive lock is used so that a single thread can acquire the
lock multiple times, and release it only when an identical number of
\'unlock()\' calls have been performed.
Args:
stream: A file-like object to store logs. Defaults to a cStringIO object.
stderr: If specified, use sys.stderr as the underlying stream.'

def __init__(self, stream=None, stderr=False):

    self._stderr = stderr
    if self._stderr:
        assert (stream is None)
    else:
        self._stream = (stream or cStringIO.StringIO())
    self._lock = threading.RLock()
    self._reset()
