当前位置:网站首页>【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
以上
边栏推荐
猜你喜欢

mapreduce概念和案例(尚硅谷学习笔记)

Take you to master the formatter of visual studio code

ssm+mysql实现进销存系统

SQLI-LABS通关(less1)

How to call WebService in PHP development environment?

Check log4j problems using stain analysis

ssm垃圾分类管理系统

Changes in foreign currency bookkeeping and revaluation general ledger balance table (Part 2)

CSRF attack

Oracle apex Ajax process + dy verification
随机推荐
腾讯机试题
pySpark构建临时表报错
SQLI-LABS通关(less2-less5)
Oracle 11g sysaux table space full processing and the difference between move and shrink
Sqli-labs customs clearance (less15-less17)
Yolov5 practice: teach object detection by hand
ssm垃圾分类管理系统
使用 Compose 实现可见 ScrollBar
读《敏捷整洁之道:回归本源》后感
IDEA2020中测试PySpark的运行出错
Laravel8中的find_in_set、upsert的使用方法
如何高效开发一款微信小程序
Module not found: Error: Can't resolve './$$_ gendir/app/app. module. ngfactory'
Differences between ts and JS
SSM学生成绩信息管理系统
SSM二手交易网站
JSP intelligent community property management system
oracle EBS标准表的后缀解释说明
叮咚,Redis OM对象映射框架来了
Explain in detail the process of realizing Chinese text classification by CNN