Open minrk opened 2 years ago
Currently is there a way to tee to both console output
and file output
in jupyter notebook? In jupyter notebook, we have cell output
, console output
and file output
. By doing like
from wurlitzer import pipes, STDOUT
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())
logger.addHandler(logging.FileHandler("mycode.log"))
with pipes(logger, stderr=STDOUT):
call_some_c_function()
I can tee to cell output
and file output
. But I haven't found a way to tee to the console output
and file output
. Using like logger.addHandler(logging.StreamHandler(sys.__stdout__))
will cause infinite loop.
Sometimes when I capture output, I want to not just redirect it, but tee it (write to both the original and redirected files, instead of only the redirected file). This could probably be a simple flag, since we already have an internal handle on the original FD for restoring later.