当前位置:网站首页>【Torch】最简洁logging使用指南
【Torch】最简洁logging使用指南
2022-07-02 06:25:00 【lwgkzl】
网上的教程大多十分复杂,实际上使用logging非常简单, 三行代码就好了
我使用logging是为了方便调试, 因为输出框缓存的数量是有限的,如果把输出打印到文件中观察使用体验会好很多,因为这三行代码的功能就是为了将输出导出到某一个文件中
配置代码如下:
import logging
logging.basicConfig(level=logging.INFO, filename='./mylog/test.log', filemode='w')这里首先引用了logging的包, 然后配置一下logging的基本配置
filename表示输出文件的位置,注意这里他无法新建文件夹,意味着这里的'mylog'这个目录你需要先创建好。
filemode='w'表示修改文件的模式,这里是指的是每一次运行文件都重新写入文件覆盖上一次运行写入的内容,更多文件的读写模式请参照: 读写模式
这样就配置好了,然后基本使用就像print一样:
logging.info('aaaa')如果想输出变量的话:使用‘f’运算符:
aa = 1
logging.info(f'aa: {aa}')用大括号把待输出变量括起来就好了,最后这些输出就存储在mylog文件夹的test.log文件中。 f运算符的使用请参照:https://blog.csdn.net/lwgkzl/article/details/107695293
以上
边栏推荐
- Pyspark build temporary report error
- JSP智能小区物业管理系统
- Oracle segment advisor, how to deal with row link row migration, reduce high water level
- Proteus -- RS-232 dual computer communication
- 【调参Tricks】WhiteningBERT: An Easy Unsupervised Sentence Embedding Approach
- MapReduce concepts and cases (Shang Silicon Valley Learning Notes)
- spark sql任务性能优化(基础)
- Take you to master the formatter of visual studio code
- 叮咚,Redis OM对象映射框架来了
- 一个中年程序员学习中国近代史的小结
猜你喜欢

DNS攻击详解

Sqli-labs customs clearance (less1)

The boss said: whoever wants to use double to define the amount of goods, just pack up and go

SSM实验室设备管理

ORACLE 11G利用 ORDS+pljson来实现json_table 效果

Ceaspectuss shipping company shipping artificial intelligence products, anytime, anywhere container inspection and reporting to achieve cloud yard, shipping company intelligent digital container contr

Explain in detail the process of realizing Chinese text classification by CNN

Oracle EBs and apex integrated login and principle analysis

CSRF攻击

ORACLE EBS 和 APEX 集成登录及原理分析
随机推荐
读《敏捷整洁之道:回归本源》后感
如何高效开发一款微信小程序
Agile development of software development pattern (scrum)
Sqli labs customs clearance summary-page1
使用 Compose 实现可见 ScrollBar
The boss said: whoever wants to use double to define the amount of goods, just pack up and go
Take you to master the formatter of visual studio code
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
使用Matlab实现:幂法、反幂法(原点位移)
搭建frp进行内网穿透
RMAN增量恢复示例(1)-不带未备份的归档日志
[leetcode question brushing day 35] 1060 Missing element in ordered array, 1901 Find the peak element, 1380 Lucky number in matrix
MySQL组合索引加不加ID
UEditor . Net version arbitrary file upload vulnerability recurrence
ORACLE APEX 21.2安装及一键部署
2021-07-17c /cad secondary development creation circle (5)
ORACLE 11G SYSAUX表空间满处理及move和shrink区别
2021-07-05c /cad secondary development create arc (4)
Data warehouse model fact table model design
Yaml file of ingress controller 0.47.0