当前位置:网站首页>【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
以上
边栏推荐
- 华为机试题
- Error in running test pyspark in idea2020
- 2021-07-17c /cad secondary development creation circle (5)
- Oracle APEX 21.2 installation et déploiement en une seule touche
- Explanation of suffix of Oracle EBS standard table
- JSP智能小区物业管理系统
- @Transational踩坑
- 实现接口 Interface Iterable<T>
- php中时间戳转换为毫秒以及格式化时间
- 【调参Tricks】WhiteningBERT: An Easy Unsupervised Sentence Embedding Approach
猜你喜欢

Take you to master the formatter of visual studio code

IDEA2020中测试PySpark的运行出错

搭建frp进行内网穿透

Sqli-labs customs clearance (less18-less20)

Sqli-labs customs clearance (less1)

Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"

Principle analysis of spark

【调参Tricks】WhiteningBERT: An Easy Unsupervised Sentence Embedding Approach

Yaml file of ingress controller 0.47.0

ssm人事管理系统
随机推荐
Sqli labs customs clearance summary-page1
Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
CSRF attack
中年人的认知科普
Oracle EBS interface development - quick generation of JSON format data
【调参Tricks】WhiteningBERT: An Easy Unsupervised Sentence Embedding Approach
@Transational踩坑
CRP implementation methodology
Oracle EBs and apex integrated login and principle analysis
Two table Association of pyspark in idea2020 (field names are the same)
MySQL无order by的排序规则因素
MapReduce concepts and cases (Shang Silicon Valley Learning Notes)
使用Matlab实现:幂法、反幂法(原点位移)
MySQL组合索引加不加ID
php中树形结构转数组(拉平树结构,保留上下级排序)
php中的二维数组去重
JSP intelligent community property management system
RMAN增量恢复示例(1)-不带未备份的归档日志
Sqli-labs customs clearance (less15-less17)
ORACLE EBS接口开发-json格式数据快捷生成