![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python中的logging使用
不起眼的程序猿
这个作者很懒,什么都没留下…
展开
-
2021-07-10
在使用python中的日志模块时会出现日志文件里的记录成线性增加(第一条记录写入一条,第二条记录写入两条…一次增加的情况) 在使用python中编写win服务的模块及ThreadingTCPServer模块时遇到上述情况 在logger方法中增加logger.handlers.clear()即可解决线性增加问题,部分代码如下: def _getLogger(): logger = logging.getLogger('[TCP]') # 添加语句防止重复写入日志内容 logger.h原创 2021-07-10 13:28:19 · 99 阅读 · 0 评论 -
2021-06-26
python中关于logging模块的使用,为代码增加写入日志(工作开发必备)代码如下: def getLogger(): # 获取一个记录器 logger = logging.getLogger('test') # 创建文件夹名称为log的文件夹 dirpath = path.dirname(__file__) + '\\log\\' # 为logger指定handler让他知道怎么处理日志,输出到哪里,日志的文件名字为test.log handler =原创 2021-06-26 16:13:56 · 67 阅读 · 0 评论