当前位置:网站首页>日志
日志
2022-04-23 05:47:00 【峰爷520】
import logging,sys
# 获取logger的实例
logger = logging.getLogger("testLoger")
# 指定logger的输出形式
formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s")
# 文件日志,终端日志
file_handler = logging.FileHandler('testLogger.log')
# 文件日志按照指定的格式来写
file_handler.setFormatter(formatter)
console_handler = logging.StreamHandler(sys.stdout)
# 文件日志按照指定的格式来写
console_handler.setFormatter(formatter)
# 把文件日志,终端日志对象添加到日志处理器logger中
logger.addHandler(file_handler)
logger.addHandler(console_handler)
logger.warning("test warning in log")
logger.removeHandler(file_handler)
logger.removeHandler(console_handler)
版权声明
本文为[峰爷520]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_41752427/article/details/81086435
边栏推荐
猜你喜欢
随机推荐
根据SQL语句查询出的结果集,将其封装为json
10.Advance Next Round
[leetcode 401] binary Watch
Problems and solutions of database migration
Solution to the trial of ycu Blue Bridge Cup programming competition in 2021
Explanation of the second I interval of 2020 Niuke summer multi school training camp
Database - sorting data
Rust的闭包类型(Fn, FnMut, FnOne的区别)
9.Life, the Universe, and Everything
Rust 的多线程安全引用 Arc
Programming training
Algèbre linéaire chapitre 1 - déterminants
GDAL+OGR学习
Mysql database foundation
Protected (members modified by protected are visible to this package and its subclasses)
[leetcode 19] delete the penultimate node of the linked list
[leetcode 202] happy number
破解滑动验证码
Optional best practices
Consistent hash algorithm used for redis cache load balancing