我真的很喜欢这个,这是你的工作例子!说真的,这太棒了!
从把这个放进你的settings.py
美元开始
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
'standard': {
'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
'datefmt' : "%d/%b/%Y %H:%M:%S"
},
},
'handlers': {
'null': {
'level':'DEBUG',
'class':'django.utils.log.NullHandler',
},
'logfile': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': SITE_ROOT + "/logfile",
'maxBytes': 50000,
'backupCount': 2,
'formatter': 'standard',
},
'console':{
'level':'INFO',
'class':'logging.StreamHandler',
'formatter': 'standard'
},
},
'loggers': {
'django': {
'handlers':['console'],
'propagate': True,
'level':'WARN',
},
'django.db.backends': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False,
},
'MYAPP': {
'handlers': ['console', 'logfile'],
'level': 'DEBUG',
},
}
}
这一切意味着什么?
- Formaters我希望它以与./manage.py runserver相同的样式出现
- 处理程序-我想要两个日志(log)-一个调试文本文件,一个信息控制台.这使我能够真正在挖洞中(如果需要)并查看文本文件,看看幕后发生了什么.
- 伐木者-这里是我们确定要伐木的地方.通常,Django会收到警告和上面的警告-例外(因此传播)是后端,我喜欢在这些后端看到SQL调用,因为它们可能会变得疯狂.最后是我的应用程序,我有两个处理程序,并将所有东西都推送到它上面.
现在我如何使MYAPP能够使用它...
根据documentation条,将其放在文件的顶部(views.py)..
import logging
log = logging.getLogger(__name__)
然后,为了把东西弄出来,就做这件事.
log.debug("Hey there it works!!")
log.info("Hey there it works!!")
log.warn("Hey there it works!!")
log.error("Hey there it works!!")
日志(log)级别解释为here,对于纯Python here则解释为日志(log)级别.