python写日志封装类实例
作者:秋风秋雨 时间:2022-07-23 22:40:47
本文实例讲述了python实现写日志封装类。分享给大家供大家参考。具体如下:
# encoding:utf-8
import sys
import logging
import time
def writeLog(message):
logger=logging.getLogger()
filename = time.strftime('%Y-%m-%d',time.localtime(time.time()))
handler=logging.FileHandler("./log/"+filename+"error")
logger.addHandler(handler)
logger.setLevel(logging.NOTSET)
logger.info(message)
if __name__ == '__main__':
writeLog("hello")
将这段代码保存为 TLog,调用的时候先import TLog,然后TLog.writelog("jb51.net")即可
希望本文所述对大家的Python程序设计有所帮助。
标签:python,日志
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python实现破解12306图片验证码的方法分析
2021-01-28 18:25:34
![](https://img.aspxhome.com/file/2023/1/115461_0s.png)
PHP设计模式(八)装饰器模式Decorator实例详解【结构型】
2023-11-24 05:59:31
![](https://img.aspxhome.com/file/2023/5/111355_0s.jpg)
自动化测试Pytest单元测试框架的基本介绍
2023-08-20 04:51:47
![](https://img.aspxhome.com/file/2023/3/70733_0s.jpg)
js 中将多个逗号替换为一个逗号的代码
2024-04-16 10:32:48
在SQL Server中将数据导出为XML和Json的方法
2024-01-12 22:10:17
![](https://img.aspxhome.com/file/2023/1/119221_0s.png)
Javascript命名禁区[110407.updated]
2011-04-28 09:48:00
python将三维数组展开成二维数组的实现
2023-01-07 06:34:30
insert和select结合实现"插入某字段在数据库中的最大值+1"的方法
2024-01-25 07:52:46
dir()、readdir()、scandir()和glob()四种遍历目录方法及性能分析
2023-05-25 11:18:27
《CSS权威指南》文摘(1)--块级元素、行内元素
2008-04-05 13:42:00
python包相关知识点之包的导入、相对路径以及绝对路径
2023-08-11 11:09:46
![](https://img.aspxhome.com/file/2023/4/103634_0s.png)
pygame实现俄罗斯方块游戏
2023-04-06 20:17:14
![](https://img.aspxhome.com/file/2023/4/68954_0s.png)
linux centos 7.x 安装 python3.x 替换 python2.x的过程解析
2021-11-27 02:46:43
![](https://img.aspxhome.com/file/2023/8/102878_0s.png)
asp如何对用户进行授权?
2009-11-20 18:46:00
python 实现批量xls文件转csv文件的方法
2023-08-29 10:25:26
Oracle row_number() over()解析函数高效实现分页
2011-12-01 10:33:07
python关于多值参数的实例详解
2023-11-05 21:43:35
解决Pycharm出现的部分快捷键无效问题
2021-09-12 12:49:34
![](https://img.aspxhome.com/file/2023/0/115800_0s.jpg)
Python使用回溯法子集树模板解决爬楼梯问题示例
2022-05-30 17:38:54
![](https://img.aspxhome.com/file/2023/6/104886_0s.jpg)
numpy ndarray 按条件筛选数组,关联筛选的例子
2021-04-12 04:58:09