我在 Heroku 上部署了一个 Django 应用程序。
我正在使用默认日志记录模块,并且我的日志在开发中正常显示,无论是 DEBUG
为 True 还是 False。
不过,当使用命令 heroku logs --tail
部署到 heroku 时,我无法看到日志。
这是我的 settings.py
文件的内容:
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'simple': {
'format': '{levelname} [{asctime}] module:{module} - {message}',
'style': '{',
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'simple',
'stream': sys.stdout,
},
},
'loggers': { # I tried replacing this with 'root'
'': {
'handlers': ['console'],
'level': 'DEBUG',
},
}
}
在我的文件中,例如 views.py
:
import logging
logger = logging.getLogger(__name__)
logging.debug('something...')
最后,在我的 Procfile
中:
release: python manage.py migrate --settings=myapp.deploy_settings
web: gunicorn myapp.wsgi --log-file -
我也尝试过使用 StackOverflow 帖子中提到的 web: gunicorn myapp.wsgi --log-file=-
,但没有成功。
这是什么原因造成的?
答案 0 :(得分:1)
将 logging=False
添加到 django_heroku.settings(locals(), logging=False)
解决了该问题。