我之前也曾问过类似的问题,但是很难获得有关问题所在的更多信息。
我有一个Django应用,它通过通道运行。 因此,Django,Daphne,Channels,NGINX,Redis
我的日志记录配置如下:
# Logging
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django': {
'handlers': ['console'],
'propagate': True,
'level': 'INFO'
},
'dashboards': {
'handlers': ['console'],
'propagate': False,
'level': 'DEBUG',
},
},
}
频道:
CHANNEL_LAYERS = {
"default": {
"BACKEND": "asgi_redis.RedisChannelLayer",
"CONFIG": {
"hosts": [("localhost", 6379)],
},
"ROUTING": "app.routing.channel_routing",
},
}
我认为:
import logging
loger = logging.getLogger(__name__)
def index(request):
loger.debug(":dsfasdfasdfasdfasdfasdfasdfasdfasdfasdf")
return render(request, 'site/index.html', context)
使用主管来管理服务
[program:Daphne]
environment=PATH="/opt/site/venv/bin"
command=/opt/site/venv/bin/daphne -b 0.0.0.0 -p 8000 site.asgi:channel_layer --proxy-headers -v2
directory=/opt/site/site
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/tmp/daphne.out.log
[program:Worker]
environment=PATH="/opt/site/venv/bin"
command=/opt/site/venv/bin/python manage.py runworker -v2
directory=/opt/site/site
process_name=%(program_name)s_%(process_num)02d
numprocs=10
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/tmp/workers.out.log
我可以在页面请求后看到工作日志,也可以看到异常记录在日志中(/tmp/workers.out.log)。
2018-12-13 21:36:22,396 - DEBUG - worker - Got message on http.request (reply daphne.response.SrXmOkzSNt!bUdAxibnQp)
2018-12-13 21:36:22,396 - DEBUG - runworker - http.request
2018-12-13 21:36:22,397 - DEBUG - worker - Dispatching message on http.request to channels.staticfiles.StaticFilesConsumer
由于某种原因,每当刷新页面时,我都不会在日志中看到调试信息。 如果重新启动worker和daphne,我会立即看到该日志记录出现在worker日志(/tmp/workers.out.log)中。
2018-12-13 21:39:02,678 - INFO - worker - Shutdown signal received while idle, terminating immediately
2018-12-13 21:39:02,679 - INFO - worker - Shutdown signal received while idle, terminating immediately
:dsfasdfasdfasdfasdfasdfasdfasdfasdfasdf
2018-12-13 21:39:02,681 - INFO - worker - Shutdown signal received while idle, terminating immediately
:dsfasdfasdfasdfasdfasdfasdfasdfasdfasdf
奇怪的是,我有另一个可以这样记录的应用程序。 有什么主意,为什么日志似乎会交出而不是直到Django worker重新启动才写?