Loguru: How to write logs to StringIo

Created on 27 Feb 2019  路  4Comments  路  Source: Delgan/loguru

I like loguru very much. but I'm using the unit test framework to generate reports to read data in StringIo. Is there any way to solve this problem??

question

All 4 comments

@flybaozi Did you find a solution? 馃槃

I'd like to know this as well.

@Zylatis It should work fine using a StringIO object as the logger sink:

from loguru import logger
from io import StringIO

stream = StringIO()

logger.remove()
logger.add(stream)

logger.info("Foo")
logger.debug("Bar: {}", 123)

print(stream.getvalue())

Are you having trouble with anything?

Hmm I definitely tried that and was having no luck, but possibly i was using .read() not .getvalue(), thanks! (might've also just had too much wine and put things in the wrong order...)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

heckad picture heckad  路  4Comments

shmilylty picture shmilylty  路  5Comments

blueyed picture blueyed  路  7Comments

jonathanhle picture jonathanhle  路  3Comments

ghost picture ghost  路  4Comments