- 只打印log
python3 a.py
- 只保存log
python3 a.py > log.log # 覆盖
python3 a.py >> log.log # 追加
- 保存的同时将信息打印在屏幕上
python3 a.py | tee ./log.log # 覆盖
python3 a.py | tee -a ./log.log # 追加
本文介绍了如何使用Python进行日志管理,包括仅打印日志、将日志保存到文件以及同时在屏幕上显示和保存日志的方法。通过`>`实现覆盖写入,`>>`实现追加写入,而`tee`命令则用于在保存日志的同时将其输出到屏幕上。
python3 a.py
python3 a.py > log.log # 覆盖
python3 a.py >> log.log # 追加
python3 a.py | tee ./log.log # 覆盖
python3 a.py | tee -a ./log.log # 追加
1312
1201
807
608

被折叠的 条评论
为什么被折叠?