python - Azure Web 服务和 Django 日志

标签 python django azure logging django-models

我在写日志时遇到了一些令人困惑的问题......

下面是我的设置.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/

相关文章:

python - cross_val_score 和 StratifiedKFold 给出不同的结果

.net - 通过电子邮件将文件上传到 Windows Azure

azure - 使用 Azure API 管理服务,如何在发送到后端 API 之前解析请求属性?

Python - 单元格类型 'NoneType' 而值在里面。怎么改造呢?

python - 用 n 表示具有整数 A i,j := sin(z i, j) 的 nxn 数组,其中 zi, j 是 (0,2pi] 中均匀分布的随机数

android - 添加默认用户图片,例如 Gmail Android App

python - 无法从登录页面进一步移动,[django-otp]

python - Django 客户端不会在测试中删除

linux - 第二个 XRDP 用户无法连接到 Azure VM 上的 GUI

python - Pymongo 不像 JSON 那样解析