Is there a way to hide the printed output inside Jupyter notebook (the red background section encircled in green) while still maintaining the info logging capabilities such as saving the logs into a.log file?
I saw threads talking about changing the LEVEL, but that is not what I am looking for since I want to keep the level at INFO to continue logging the INFO logs.
FYI the display in red in Jupyter is from the sys.stderr
stream. What you are looking for is to perform logging that writes to file without writing to STDERR.
Following docs for the logging standard library , you can set up a logger that writes to a FileHandler, as below:
import logging
logger = logging.getLogger('my_application')
logger.setLevel(logging.DEBUG)
fh = logging.FileHandler('my_log_file.log')
fh.setLevel(logging.DEBUG)
logger.addHandler(fh)
# Does not write to sys.stderr
logger.info("These logs do not show up on Jupyter!")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.