看板 Python 關於我們 聯絡資訊
: → 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
MoriUmi: 請問你有在views.py開頭寫寫入log file的程式碼嗎?你沒 07/28 21:47
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
MoriUmi: logging.getLogger(__name__) 裡面的__name__要代換成指 07/29 20:07
MoriUmi: 定的app名稱 07/29 20:07
MoriUmi: 例如你上面寫的 'myproject' 07/29 20:10