当前位置:网站首页>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
边栏推荐
- 摩托罗拉诉海能达案一审结果出炉:海能达被判赔53亿元
- 2022/3/11 exam summary
- Understanding and use of third-party library
- Do you want to be dismissed? Let's take a look at the "exit tips" of programmers
- Pyqt5 rapid development and practice 4.10 window drawing controls
- Tips and extensions of graph theory
- 2022年软件开发的趋势
- `What is the difference between SSH -y` (trusted X11 forwarding) and 'SSH -x` (untrusted X11 forwarding)?
- 知乎数据分析训练营全能班
- Oppo find x2 series release: 3k+120hz curved screen, DxO score first, top version 6999 yuan!
猜你喜欢

On data management of data warehouse

Pyqt5 rapid development and practice 4.9 dialog controls

网络开发套接字以及UDP、TCP协议

智能家居浪潮来袭,如何让机器看懂世界 【结尾有资料】

4 轮拿下字节 Offer,面试题复盘

浅析云原生应用安全组织架构

JVM composition and memory model

Three consecutive high-frequency interview questions of redis online celebrity: cache penetration? Cache breakdown? Cache avalanche?

Video human behavior detection

一篇搞定Redis中的BigKey问题
随机推荐
Leetcode-470. implement rand10() with rand7()
紫光FPGA解决口罩难题!助力口罩生产全面提速
Leetcode-461. Hamming distance
Px4 module design part 13: workqueue design
Solve the problem that the last bit of IP address access is odd and even, or even and odd (the problem encountered when the cloud encryption machine connects to the cloud server, the whole process is
摩托罗拉诉海能达案一审结果出炉:海能达被判赔53亿元
传华为再度砍单!供应链厂商更难了
我与消息队列的八年情缘
Summary of exam on May 17, 2022
深度剖析 —— 文件操作
cron 表达式
网络开发套接字以及UDP、TCP协议
Purple light FPGA solves the mask problem! Boost the overall speed-up of mask production
Three consecutive high-frequency interview questions of redis online celebrity: cache penetration? Cache breakdown? Cache avalanche?
初中三年回忆录
Convnext:a convnet for the 2020s - model Brief
Object creation process and object layout
Feed流应用重构-架构篇
If there is no reference ground at all, guess if you can control the impedance?
The prefix is not removed when zuul gateway automatically routes