当前位置:网站首页>【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
以上
边栏推荐
猜你喜欢
2021-07-05C#/CAD二次开发创建圆弧(4)
SQLI-LABS通關(less6-less14)
TCP attack
Pratique et réflexion sur l'entrepôt de données hors ligne et le développement Bi
IDEA2020中测试PySpark的运行出错
CAD secondary development object
Changes in foreign currency bookkeeping and revaluation general ledger balance table (Part 2)
Check log4j problems using stain analysis
Sqli-labs customs clearance (less6-less14)
Only the background of famous universities and factories can programmers have a way out? Netizen: two, big factory background is OK
随机推荐
Differences between ts and JS
Sqli-labs customs clearance (less15-less17)
php中计算两个日期之前相差多少天、月、年
如何高效开发一款微信小程序
Changes in foreign currency bookkeeping and revaluation general ledger balance table (Part 2)
ARP攻击
ORACLE APEX 21.2安装及一键部署
Sqli-labs customs clearance (less1)
UEditor . Net version arbitrary file upload vulnerability recurrence
SQLI-LABS通关(less1)
SQL injection closure judgment
Oracle general ledger balance table GL for foreign currency bookkeeping_ Balance change (Part 1)
Sqli labs customs clearance summary-page4
Laravel8中的find_in_set、upsert的使用方法
数仓模型事实表模型设计
Ceaspectuss shipping company shipping artificial intelligence products, anytime, anywhere container inspection and reporting to achieve cloud yard, shipping company intelligent digital container contr
Error in running test pyspark in idea2020
优化方法:常用数学符号的含义
Three principles of architecture design
sqli-labs通關匯總-page2