【问题标题】:Gunicorn: Access logs to a file instead of StndoutGunicorn:将日志访问到文件而不是 Stndout
【发布时间】:2019-02-05 03:49:36
【问题描述】:

我正在使用以下版本的 Python、Django 和 Gunicorn 使用 Digitalocean 一键式 Django 服务器部署。

gunicorn (version 19.7.1)

python 2.7

我似乎不知道如何将访问日志记录到文件中。下面是我的 gunicorn.service 文件。

[Unit]
Description=Gunicorn daemon for Django Project
Before=nginx.service
After=network.target

[Service]
WorkingDirectory=/home/django/egre
ExecStart=/usr/bin/gunicorn --name=egre --pythonpath=/home/django/egre --bind unix:/home/django/gunicorn.socket --config /etc/gunicorn.d/gunicorn.py --access-logfile /var/log/emperor.log eGRE.wsgi:application
Restart=always
SyslogIdentifier=gunicorn
User=django
Group=django


[Install]
WantedBy=multi-user.target

https://docs.gunicorn.org/en/19.7.1/settings.html#logging

遵循上述文档后,我尝试使用--access-logfile=-,它可以工作,但在传递相对路径后不会将我的标准输出记录到文件中,gunicorn 不会重新启动并给出退出代码 1。

如何将日志写入emerge.log?

【问题讨论】:

    标签: django gunicorn digital-ocean


    【解决方案1】:

    我认为你可以尝试使用django's logging

    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'handlers': {
            'file': {
                'level': 'DEBUG',
                'class': 'logging.FileHandler',
                'filename': '/path/to/logger/gunicorn_access.log',
            },
        },
        'loggers': {
            'gunicorn.access': {
                'handlers': ['file'],
                'level': 'DEBUG',
                'propagate': True,
            },
        },
    }
    

    【讨论】:

    • Gunicorn 在复制粘贴上述 sn-p 后启动和停止。我在上面的文件名位置添加了文件。你能告诉我我会错过什么吗?就像不执行 gunicorn 文件而只执行 ExecStart 命令一样,一切正常。我缺少与用户相关的内容?
    • 它是否显示任何错误?另外,您是否有权在这些目录中写入日志?
    • 已加载:已加载(/etc/systemd/system/gunicorn.service;已启用;供应商预设:已启用)活动:自 2019 年 2 月 5 日星期二 21:35 起失败(结果:退出代码) :25 世界标准时间; 2s 前 进程:28360 ExecStart=/usr/bin/gunicorn --name=egre --pythonpath=/home/django/egre --bind 0.0.0.0:8000 --config /etc/gunicorn Main PID: 28360 (code=已退出,状态=1/FAILURE)
    • 嗯,这个错误不是很有帮助。我假设它是一个文件写入权限问题(虽然不确定)。
    猜你喜欢
    • 2018-05-21
    • 2018-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多