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

JSP智能小区物业管理系统

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

搭建frp进行内网穿透

TCP attack

软件开发模式之敏捷开发(scrum)

Oracle apex Ajax process + dy verification

Two table Association of pyspark in idea2020 (field names are the same)

Error in running test pyspark in idea2020

UEditor . Net version arbitrary file upload vulnerability recurrence

sqli-labs通关汇总-page2
随机推荐
ORACLE EBS接口开发-json格式数据快捷生成
Oracle segment advisor, how to deal with row link row migration, reduce high water level
Sqli-labs customs clearance (less15-less17)
ORACLE 11.2.0.3 不停机处理SYSAUX表空间一直增长问题
Oracle apex Ajax process + dy verification
Alpha Beta Pruning in Adversarial Search
Spark的原理解析
2021-07-19c CAD secondary development creates multiple line segments
A summary of a middle-aged programmer's study of modern Chinese history
Oracle rman自动恢复脚本(生产数据向测试迁移)
使用MAME32K进行联机游戏
Go package name
Cloud picture says | distributed transaction management DTM: the little helper behind "buy buy buy"
php中计算树状结构数据中的合计
Ingress Controller 0.47.0的Yaml文件
Module not found: Error: Can't resolve './$$_ gendir/app/app. module. ngfactory'
php中生成随机的6位邀请码
ssm人事管理系统
MySQL无order by的排序规则因素
Sqli-labs customs clearance (less6-less14)