Pay*_*ian 5 django graphql graphene-python
DEBUG我在使用 Graphene 和 Django 查看级别日志时遇到问题。我已设置以下内容settings.py:
\nLOGGING = {\n \'version\': 1,\n \'disable_existing_loggers\': False,\n \'handlers\': {\n \'console\': {\n \'class\': \'logging.StreamHandler\',\n },\n },\n \'loggers\': {\n \'django\': {\n \'handlers\': [\'console\'], \n \'level\': \'DEBUG\'\n },\n \'django.request\': {\n \'handlers\': [\'console\'],\n \'level\ ': \'调试\'\n },\n },\n}\n\n\n然而,当我尝试查看 Django 服务器的日志时,我看到的只是:
\n\n\n \xe2\x9d\xaf\xe2\x9d\xaf\xe2\x9d\xaf kubectl messages -f server-6b65f48895-bmp6w server\n要执行的操作:\n 应用所有迁移:admin、auth、contenttypes、django_celery_beat、django_celery_results 、服务器、会话、social_django\n运行迁移:\n 没有要应用的迁移。\n正在执行系统检查...\n\n系统检查未发现任何问题(0 已静音)。\n2018 年 10 月 8 日 - 23:59:00\nDjango版本 2.0.6,使用设置 \'backend.settings\'\n在 http://0.0.0.0:8000/\n启动开发服务器\n使用 CONTROL-C 退出服务器。\n"POST /graphql HTTP/1.1" 400 113 \n“POST /graphql HTTP/1.1”400 113\n“POST /graphql HTTP/1.1”400 113\n“POST /graphql HTTP/1.1”400 113\n“POST /graphql HTTP/1.1”400 113\n “POST /graphql HTTP/1.1” 400 113\n“POST /graphql HTTP/1.1” 400 113\n“POST /graphql HTTP/1.1” 400 113\n“POST /graphql HTTP/1.1” 400 113\n“POST /graphql HTTP/1.1" 400 113\n\n\n
我怎样才能查看DEBUG级别日志以找出为什么我的服务器持续服务 400 秒?
我有姜戈DEBUG环境变量。我正在尝试调试生产问题。
不久前我也遇到了同样的问题,并找到了解决方法:
from promise import is_thenable
class DebugMiddleware(object):
def on_error(self, error):
print(error)
def resolve(self, next, root, info, **args):
result = next(root, info, **args)
if is_thenable(result):
result.catch(self.on_error)
return result
Run Code Online (Sandbox Code Playgroud)
并告诉graphene将其用作中间件:
GRAPHENE = {
...
'MIDDLEWARE': [
'path.to.containing.module.DebugMiddleware',
...
]
}
Run Code Online (Sandbox Code Playgroud)
在这里您可以访问解析时引发的错误。
最初的问题(没有模块日志记录)可能是由禁用的记录器引起的graphql,但我在这个方向上的探索没有任何结果:(