我在写日志时遇到了一些令人困惑的问题......
下面是我的设置.py:
DEBUG = True
TEMPLATE_DEBUG = DEBUG
.....
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
},
'logfile': {
'level': 'INFO',
'class': 'logging.handlers.RotatingFileHandler',
'filename': os.getenv('LOGFILE', 'django.log')
}
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
'django': {
'handlers': ['logfile'],
'level': 'INFO',
'propagate': False,
}
}
}
** 我想将所有 INFO 消息传递到 django.log。
当我在本地主机测试上运行服务器时,它将正确写入 django.log。
在我发布到 Azure Web 应用服务并设置“应用程序设置”=>“应用程序设置”后,添加新路径 LOGFILE D:\home\site\wwwroot\logfiles\django.log。 enter image description here
我向我的应用程序服务发送了一些请求,然后登录 DebugConsole 来查看 D:\home\site\wwwroot\logfiles\django.log 文件。 enter image description here
这个日志文件(django.log)中没有任何内容,我尝试在DebugConsole修改它,会出现ERROR 409confict: Could not write to local resources 'D:\home\site\wwwroot\logfiles\django.log' 由于错误“该进程无法访问文件 'D:\home\site\wwwroot\logfiles\django.log',因为它正在被另一个进程使用。”。
Django 似乎无法在 django.log 中写入任何内容或权限问题?我能怎么做? 有人可以帮忙解决这个问题吗?
最佳答案
我也遇到过类似的问题。我在这里找到了解决方案: http://azaleasays.com/2014/05/01/django-logging-with-rotatingfilehandler-error/
简而言之:启动服务器: python manage.py runserver --noreload
关于python - Azure Web 服务和 Django 日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40628185/