Re: [問題] Django internal error 500 debug

看板Python作者 (.)時間9年前 (2016/07/28 15:56), 9年前編輯推噓3(302)
留言5則, 1人參與, 最新討論串3/3 (看更多)
: → 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://www.ptt.cc/bbs/Python/M.1469692595.A.006.html

07/28 21:47, , 1F
請問你有在views.py開頭寫寫入log file的程式碼嗎?你沒
07/28 21:47, 1F

07/28 21:47, , 2F
寫東西進去檔案當然沒東西
07/28 21:47, 2F
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

07/29 20:07, , 3F
logging.getLogger(__name__) 裡面的__name__要代換成指
07/29 20:07, 3F

07/29 20:07, , 4F
定的app名稱
07/29 20:07, 4F

07/29 20:10, , 5F
例如你上面寫的 'myproject'
07/29 20:10, 5F
文章代碼(AID): #1NcRgp06 (Python)
文章代碼(AID): #1NcRgp06 (Python)