作者sean72 (.)
看板Python
标题Re: [问题] Django internal error 500 debug
时间Thu Jul 28 15:56:31 2016
: → kenduest: 你没开 log 记录吗 ? 07/27 08:31
: → kenduest: https://docs.djangoproject.com/en/1.9/topics/logging 07/27 08:32
: → kenduest: 开 LOGGING 之後一般语法问题等可直接可以在档案内看到 07/27 08:32
按照doc
在setting.py里面设定LOGGING
我可以看到python call stack traceback error了(in both console and log file)
也可以看到debug level讯息 例如sql query
但是我在view.py 里面加入
import logging
logger = logging.getLogger(__name__)
logger.debug("debug Hey there it works!!")
logger.info("info Hey there it works!!")
logger.warn("warn Hey there it works!!")
logger.error("error Hey there it works!!")
这些讯息只会出现在console
但是并不会出现在我的log file
我找不出我的LOGGING setting哪边有问题
麻烦大家帮我看看我下面的设定
LOGGING = {
'version': 1,
'disable_existing_loggers': False ,
'handlers': {
'file1': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': BASE_DIR + '/log/debug.log',
},
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django': {
'handlers': ['file1', 'console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'),
'propagate': True,
},
'myproject': {
'handlers': ['file1', 'console'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'DEBUG'),
'propagate': True,
},
},
}
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 172.89.32.145
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1469692595.A.006.html
1F:推 MoriUmi: 请问你有在views.py开头写写入log file的程式码吗?你没 07/28 21:47
2F:→ MoriUmi: 写东西进去档案当然没东西 07/28 21:47
https://goo.gl/mQfrjw
我按照doc
先import logging
再来产生logger instance
logger = logging.getLogger(__name__)
然後就开始使用
logger.error('abcdefg')
这样对吧?
※ 编辑: sean72 (204.96.168.3), 07/28/2016 23:27:27
3F:推 MoriUmi: logging.getLogger(__name__) 里面的__name__要代换成指 07/29 20:07
4F:→ MoriUmi: 定的app名称 07/29 20:07
5F:推 MoriUmi: 例如你上面写的 'myproject' 07/29 20:10