django logging日志优先级
原创博文 转载请注明出处!
参考官方文档:https://docs.djangoproject.com/en/2.1/topics/logging/
Loggers¶
A logger is the entry point into the logging system. Each logger is a named bucket to which messages can be written for processing.
A logger is configured to have a log level. This log level describes the severity of the messages that the logger will handle. Python defines the following log levels:
DEBUG: Low level system information for debugging purposesINFO: General system informationWARNING: Information describing a minor problem that has occurred.ERROR: Information describing a major problem that has occurred.CRITICAL: Information describing a critical problem that has occurred.Each message that is written to the logger is a Log Record. Each log record also has a log level indicating the severity of that specific message. A log record can also contain useful metadata that describes the event that is being logged. This can include details such as a stack trace or an error code.
When a message is given to the logger, the log level of the message is compared to the log level of the logger. If the log level of the message meets or exceeds the log level of the logger itself, the message will undergo further processing. If it doesn’t, the message will be ignored.
Once a logger has determined that a message needs to be processed, it is passed to a Handler.
向 logger 发出 log 时,会将 message 的日志级别与 logger 的日志级别进行比较。如果 log 的级别达到或超过 logger 本身的日志级别,则 log 将进行进一步处理。如果没有,则将忽略该消息。
一旦 logger 确定需要处理 log ,它就会传递给 Handlers 。
个人理解:logger 上设定的 level 是指此种 logger 处理的最低级别,所处理的 log 信息必须要达到这个级别以上
Handlers¶
The handler is the engine that determines what happens to each message in a logger. It describes a particular logging behavior, such as writing a message to the screen, to a file, or to a network socket.
Like loggers, handlers also have a log level. If the log level of a log record doesn’t meet or exceed the level of the handler, the handler will ignore the message.
A logger can have multiple handlers, and each handler can have a different log level. In this way, it is possible to provide different forms of notification depending on the importance of a message. For example, you could install one handler that forwards
ERRORandCRITICALmessages to a paging service, while a second handler logs all messages (includingERRORandCRITICALmessages) to a file for later analysis.
handlers也具有日志级别。如果记录的 log 级别未达到或超过 handler 的级别,则 handler 将忽略该消息。
综上理解:要记录的Log 需要先达到 logger 设定的 level,然后开始 handlers 处理,level 级别达到了的所有 handles 将对此 log 进行处理,否则忽略。
# demo 1:
# setting.py
'handlers': {
'default': {
'level': 'INFO', # 'default'处理器规定处理的最低级别 低于这个级别不处理
'class': 'logging.FileHandler',
'filename': 'logging.log', # log file name
'formatter': 'simple'
},
},
# 记录器
'loggers': {
'django': {
'handlers': ['default'],
'level': 'DEBUG', # 进入'django'这个记录器 的 log 需要的最低级别,低于这个级别不记录
'propagate': False # propagate 向不向更高級別的 loggers 傳遞
}
}, # view.py
logger = logging.getLogger("django")
logger.debug(' index debug---------------\n') # 不记录 级别不够进入 handlers
logger.info(' index info---------------\n') # 记录
logger.warning(' index warning-------------\n') # 记录 # -------------------------------------------------------------
# demo 2
# setting.py
'handlers': {
'default': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': 'logging.log', # log file name
'formatter': 'simple'
},
},
# 记录器
'loggers': {
'django': {
'handlers': ['default'],
'level': 'INFO',
'propagate': False # propagate 向不向更高級別的 loggers 傳遞
}
},
# view.py
logger = logging.getLogger("django")
logger.debug(' index debug---------------\n') # 不记录 loggers 级别不够
logger.info(' index info---------------\n') # 记录
logger.warning(' index warning-------------\n') # 记录
个人test
有不对的地方欢迎指出
django logging日志优先级的更多相关文章
- Django—logging日志
简介 Django使用python自带的logging 作为日志打印工具.简单介绍下logging. logging 是线程安全的,其主要由4部分组成: Logger 用户使用的直接接口,将日志传递给 ...
- python - django (logging 日志配置和简单使用)
1. settings 配置 # 配置日志 LOGGING = { 'version': 1, 'disable_existing_loggers': True, 'formatters': { 's ...
- python的日志模块:logging;django的日志系统;django日志输出时间修改
Django的log,主要是复用Python标准库中的logging模块,在settings.py中进行配置 源代码 1.__init__.py包含以下类: StreamHandler Formatt ...
- django中介模型,CBV模型,及logging日志配制
1.中介模型 中介模型,这个是在我们创建表格时,多对多添加的时候应用到的,通过制定ManyToManyField字段中的through参数来定义,为两者的关系新建一个中介class 为什么会产生这个中 ...
- Django 的 logging日志文件配置
在Django的settings配置文件里配置以下信息: import os BASE_LOG_DIR = os.path.join(BASE_DIR , "log") # log ...
- ModelViewSet 路由 / django logging配置 / django-debug-toolbar使用
一.ModelViewSet 路由 因为我们正在使用ViewSet代替View,实际上已经不再需要自己来设计URL的配置了.将资源和视图.URL绑定到一起是一个可以自动完成的过程,只需要使用Route ...
- form,ajax注册,logging日志使用
一.form表单类型提交注册信息 二.ajax版本提交注册信息 <!DOCTYPE html> <html lang="en"> <head> ...
- 【转】python模块分析之logging日志(四)
[转]python模块分析之logging日志(四) python的logging模块是用来写日志的,是python的标准模块. 系列文章 python模块分析之random(一) python模块分 ...
- python模块分析之logging日志(四)
前言 python的logging模块是用来设置日志的,是python的标准模块. 系列文章 python模块分析之random(一) python模块分析之hashlib加密(二) python模块 ...
随机推荐
- [Xcode 实际操作]六、媒体与动画-(4)使用CoreImage框架更改图片的色相
目录:[Swift]Xcode实际操作 本文将演示如何使用CoreImage框架,调整图片的色相. 通过调整图像的色相,使图像产生暖色效果. 在项目导航区,打开视图控制器的代码文件[ViewContr ...
- 爬虫之scapy
一 介绍 Scrapy一个开源和协作的框架,其最初是为了页面抓取 (更确切来说, 网络抓取 )所设计的,使用它可以以快速.简单.可扩展的方式从网站中提取所需的数据.但目前Scrapy的用途十分广泛,可 ...
- tableview中用动画效果改变cell的高度
我们要的效果大概就是如下效果: 当我们选择一个cell的时候,我们就要改变它的高度,并且以动画的形式. 我们该如何实现这个效果呢?我们主要需要使用以下这两个方法: - (CGFloat)tableVi ...
- .NET 基础 一步步 一幕幕[XML基础操作]
XML可扩展标记语言,标准通用标记语言的子集,是一种用于标记电子文件使其具有结构性的标记语言. 什么是XML,学他有什么用? 优点:容易读懂,格式标准任何语言都内置了XML分析引擎,不用单独进行文件分 ...
- 老男孩IT教育-每日一题汇总
老男孩IT教育-每日一题汇总 第几天 第几周 日期 快速访问链接 第123天 第二十五周 2017年8月25日 出现Swap file….already exists以下错误如何解决? 第122天 2 ...
- HDU 1024 A - Max Sum Plus Plus DP + 滚动数组
http://acm.hdu.edu.cn/showproblem.php?pid=1024 刚开始的时候没看懂题目,以为一定要把那n个数字分成m对,然后求m对中和值最大的那对 但是不是,题目说的只是 ...
- 机器学习框架ML.NET学习笔记【5】多元分类之手写数字识别(续)
一.概述 上一篇文章我们利用ML.NET的多元分类算法实现了一个手写数字识别的例子,这个例子存在一个问题,就是输入的数据是预处理过的,很不直观,这次我们要直接通过图片来进行学习和判断.思路很简单,就是 ...
- SLF4J user manual 专题
System Out and Err Redirected to SLF4J The sysout-over-slf4j module allows a user to redirect all ca ...
- filter配置多个url-pattern和排除个别servlet
转载自:https://blog.csdn.net/hanghangde/article/details/51298221 侵删 最近做项目遇到一个Filter需要配置多个url-pattern,上网 ...
- android dialog style属性设置
<!--最近做项目,用到alertDialog,用系统自带的style很难看,所以查了资料自己定义了个style. res/value/style.xml内增加以下代码:--> <s ...