当前位置:网站首页>logging 高级使用
logging 高级使用
2022-07-26 10:50:00 【亚索不会吹风】
import logging
''' %(name)s Logger的名字 #也就是其中的.getLogger里的路径,或者我们用他的文件名看我们填什么 %(levelno)s 数字形式的日志级别 #日志里面的打印的对象的级别 %(levelname)s 文本形式的日志级别 #级别的名称 %(pathname)s 调用日志输出函数的模块的完整路径名,可能没有 %(filename)s 调用日志输出函数的模块的文件名 %(module)s 调用日志输出函数的模块名 %(funcName)s 调用日志输出函数的函数名 %(lineno)d 调用日志输出函数的语句所在的代码行 %(created)f 当前时间,用UNIX标准的表示时间的浮 点数表示 %(relativeCreated)d 输出日志信息时的,自Logger创建以 来的毫秒数 %(asctime)s 字符串形式的当前时间。默认格式是 “2003-07-08 16:49:45,896”。逗号后面的是毫秒 %(thread)d 线程ID。可能没有 %(threadName)s 线程名。可能没有 %(process)d 进程ID。可能没有 %(message)s用户输出的消息 '''
''' Loggers:记录器,提供应用程序代码能直接使用的接口; Handlers:处理器,将记录器产生的日志发送至目的地; Filters:过滤器,提供更好的粒度控制,决定哪些日志会被输出; Formatters:格式化器,设置日志内容的组成结构和消息字段。 '''
'''创建logger记录器'''
logger = logging.getLogger('root')
# 这个记录器设置的展示日志级别的优先级最高,要设置下debug级别,
# 不然不管下面的怎么设置,都只会展示默认的warning级别日志
logger.setLevel(logging.DEBUG)
'''处理器可以单独设置要展示的日志级别,但是优先级比记录器的要低'''
'''创建一个控制台处理器'''
cmdHandler = logging.StreamHandler()
cmdHandler.setLevel(logging.DEBUG)
'''创建文件处理器'''
fileHandler = logging.FileHandler(r'D:\python\log\test.log', 'w')
fileHandler.setLevel(logging.INFO)
'''创建格式化输出日志'''
# formatter = logging.Formatter("[%(levelname)s]%(asctime)s %(name)s %(filename)s %(lineno)d %(funcName)s :%(message)s",
# datefmt='%Y-%m-%d %H:%M:%S')
formatter = logging.Formatter("[%(levelname)s] - %(asctime)s - %(message)s", datefmt='%Y-%m-%d %H:%M:%S')
'''给处理器设置格式,也就是打印日志要展示的一些信息'''
cmdHandler.setFormatter(formatter)
fileHandler.setFormatter(formatter)
'''记录器设置处理器,也就是设置打印日志的位置'''
logger.addHandler(cmdHandler)
logger.addHandler(fileHandler)
# logger.debug('debug message')
# logger.info('info message')
# logger.warning('warning message')
# logger.error('error message')
# logger.critical('critical message')
边栏推荐
- 27.移除元素
- 1837.K进制表示下的各位数字总和
- 【小程序】onReachBottom 事件为什么不能触发 ?(一秒搞定)
- @The difference and use of jsonformat and @datetimeformat
- Disable usbjatg in Altium Designer
- 公司项目中的biz层和manager层是干啥的
- Halcon模板匹配之Shape
- mysql20210906
- Constructors, method overloads, object arrays, and static
- Sword finger offer (49): convert a string to an integer
猜你喜欢

Kali view IP address
![[leetcode daily question 2021/2/13]448. Find all the missing numbers in the array](/img/9b/624416fa6a408bf64ca5438273176b.png)
[leetcode daily question 2021/2/13]448. Find all the missing numbers in the array

PLC与伺服电机连接

Disable usbjatg in Altium Designer

很多人都不清楚自己找的是Kanban软件还是看板软件

Why do I need automated testing? Software testers take you to evaluate different software testing tools
![Error[pe147]: declaration is incompatible with 'error problem](/img/4f/57145d78f4dc1fe84d2f271dd9d82f.png)
Error[pe147]: declaration is incompatible with 'error problem

使用Selenium抓取zabbix性能监控图

二叉树的遍历 递归+迭代

Newbie sees the source code arraydeque
随机推荐
Bash shell学习笔记(二)
px2rem-loader将px转化为rem,适配移动端vant-UI等框架
访问权限——private,public,protected
344.反转字符串
菜鸟看源码之ArrayDeque
MFC picture control
MFC多线程的简单使用
Sql Server 数据库之完整性约束
list升序和降序
Wechat official account development obtains openid times error 40029 invalid code solution
Wechat official account message notice "errCode": 40164, "errmsg": "invalid IP
[leetcode daily question 2021/5/8]1723. The shortest time to complete all work
@Notblank, @notnull, @notempty differences and uses
Pengge C language 20210811 program structure operation
Sword finger offer (8): jump the steps
@Validated 和 @Valid 的真正区别和使用方式
如何组装一个注册中心?
35. Search the insertion position
2021-08-13 learn C language with pengge - array
母亲