当前位置:网站首页>Jupyter notebook solves the problem that printing information cannot be viewed after closing the browser
Jupyter notebook solves the problem that printing information cannot be viewed after closing the browser
2022-07-27 23:01:00 【Go crazy first.】
One 、 Problem description
In the browser, we close the model we are training after printing , Open it again and you can see that there is no information output . In addition to handling cache methods , We can use python Of logging Output log .
Two 、 Code writing
import logging
import sys
import datetime
def init_logger(filename, logger_name):
'''
@brief:
initialize logger that redirect info to a file just in case we lost connection to the notebook
@params:
filename: to which file should we log all the info
logger_name: an alias to the logger
'''
# get current timestamp
timestamp = datetime.datetime.utcnow().strftime('%Y%m%d_%H-%M-%S')
logging.basicConfig(
level=logging.INFO,
format='[%(asctime)s] %(name)s {%(filename)s:%(lineno)d} %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(filename=filename),
logging.StreamHandler(sys.stdout)
]
)
# Test
logger = logging.getLogger(logger_name)
logger.info('### Init. Logger {} ###'.format(logger_name))
return logger
# Initialize
my_logger = init_logger("./ml_notebook.log", "ml_logger")Print out each time, such as :
my_logger.info("XXX")Another example is to record the last cell Time and output of , Print to the log file , For example, in the first cell in :
%%capture out
%%timeit
a = 1+1And then next cell in :
my_logger.info("capture & timeit: " + out.stdout)You can know the last cell Running time and content .
Reference resources :
logging — Logging facility for Python — Python 3.10.5 documentation
边栏推荐
猜你喜欢

物联网架构完全指南

It's time to say goodbye gracefully to nullpointexception

Pyqt5 rapid development and practice 4.9 dialog controls

数据仓库项目从来不是技术项目

细胞CLE19多肽荧光成像牛血清白蛋白荧光猝灭量子点的制备

Tips and extensions of graph theory

可能导致索引失效的原因

Understanding and use of third-party library

Pyqt5 rapid development and practice 4.10 window drawing controls

jvm组成及内存模型
随机推荐
摩托罗拉诉海能达案一审结果出炉:海能达被判赔53亿元
Zhihu data analysis training camp all-round class
51 MCU internal peripherals: real time clock (SPI)
10 years of technical career, those technical books that make me excited
Real time Bi (III) technical implementation of offline data and real-time data processing
2022 / 4 / 11 exam summary
[NOI2018]归程(Kruskal重构树/可持久化并查集)
In depth analysis - file operation
我与消息队列的八年情缘
浅谈数仓的数据治理
2022/5/18 exam summary
MySQL的B+Tree索引到底是咋回事?聚簇索引到底是如何长高的?
Another fire broke out in Samsung storage factory!
leetcode-461.汉明距离
The ASML lithography machine purchased by SMIC international entered the factory smoothly, but it is not a non EUV lithography machine!
Cy3荧光标记抗体/蛋白试剂盒 (10~100mg标记量)
An article to solve the bigkey problem in redis
It is said that Intel will adopt TSMC 6nm EUV process next year
Android 11 security policy and permission management
Promise解决异步