[英]What type of object is manipulated by logging filters?
我目前正在仔細研究Django日志記錄過濾器 。
在他們的一個示例中,他們定義了這種過濾方法:
from django.http import UnreadablePostError
def skip_unreadable_post(record):
if record.exc_info:
exc_type, exc_value = record.exc_info[:2]
if isinstance(exc_value, UnreadablePostError):
return False
return True
我想進一步過濾,但是我需要知道此record
參數中包含的內容,以便可以對其進行操作。
原來是LogRecord 。 可以通過系統地打印所述record
屬性來找到,如下所示:
def print_record(record):
print '>>> %s' % type(record)
return True
LOGGING = {
[...]
'filters': {
'print_record': {
'()': 'django.utils.log.CallbackFilter',
'callback': print_record,
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'filters': ['print_record'],
'formatter': 'verbose',
},
},
'loggers': {
'': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': True,
},
},
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.