Source code for pyquickhelper.loghelper.buffered_flog

"""
Buffer as a logging function.


:githublink:`%|py|5`
"""
from io import StringIO


[docs]class BufferedPrint: """ Buffered display. Relies on :epkg:`*py:io:StringIO`. Use it as follows: .. runpython:: :showcode: def do_something(fLOG=None): if fLOG: fLOG("Did something.") return 3 from pyquickhelper.loghelper import BufferedPrint buf = BufferedPrint() do_something(fLOG=buf.fprint) print(buf) :githublink:`%|py|25` """
[docs] def __init__(self): "constructor" self.buffer = StringIO()
[docs] def fprint(self, *args, **kwargs): "print function" mes = " ".join(str(_) for _ in args) self.buffer.write(mes) self.buffer.write("\n")
[docs] def __str__(self): "Returns the content." return self.buffer.getvalue()