Django记录权限错误[Errno 13]权限被拒绝

时间:2016-05-26 13:27:59

标签: python django docker

我在管理员添加日志记录到我的Django应用程序时遇到权限问题。问题似乎与日志的权限有关。我只给了777作为测试'在我的Docker文件上,我仍然有权限问题,为什么?

错误:

Traceback (most recent call last):
  File "/usr/local/lib/python3.4/logging/config.py", line 557, in configure
    handler = self.configure_handler(handlers[name])
  File "/usr/local/lib/python3.4/logging/config.py", line 725, in configure_handler
    result = factory(**kwargs)
  File "/usr/local/lib/python3.4/logging/handlers.py", line 150, in __init__
    BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/local/lib/python3.4/logging/handlers.py", line 57, in __init__
    logging.FileHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/local/lib/python3.4/logging/__init__.py", line 1006, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/local/lib/python3.4/logging/__init__.py", line 1035, in _open
    return open(self.baseFilename, self.mode, encoding=self.encoding)
PermissionError: [Errno 13] Permission denied: '/var/projects/app/logs/main_debug.log'

Docker权限:

RUN groupadd webapps
RUN useradd webapp -G webapps

RUN mkdir -p /var/log/webapp/ && chmod 777 /var/log/webapp/
RUN mkdir -p /var/run/webapp/ && chmod 777 /var/run/webapp/
RUN mkdir -p /var/projects/app/logs/ && chmod 777 /var/projects/app/logs/

监:

[program:webapp]
directory=/var/projects/app/
environment=DJANGO_SETTINGS_MODULE="app.settings"
command=gunicorn app.core.wsgi:application -c /var/projects/app/docker/gunicorn.conf
user=webapp
autostart=true
autorestart=true
stdout_logfile = /var/log/app/gunicorn_supervisor.log             ; Where to write log messages
redirect_stderr=True

记录Django:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        },
        'require_debug_true': {
            '()': 'django.utils.log.RequireDebugTrue'
        }
    },
    'formatters': {
        'main_formatter': {
            'format': '%(levelname)s:%(name)s: %(message)s '
                      '(%(asctime)s; %(filename)s:%(lineno)d)',
            'datefmt': "%Y-%m-%d %H:%M:%S",
        },
    },
    'handlers': {
        'mail_admins': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django.utils.log.AdminEmailHandler'
        },
        'console': {
            'level': 'INFO',
            'filters': ['require_debug_true'],
            'class': 'logging.StreamHandler',
            'formatter': 'main_formatter',
        },
        'production_file': {
            'level': 'INFO',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': 'logs/main.log',
            'maxBytes': 1024 * 1024 * 5,  # 5 MB
            'backupCount': 7,
            'formatter': 'main_formatter',
            'filters': ['require_debug_false'],
        },
        'debug_file': {
            'level': 'DEBUG',
            'class': 'logging.handlers.RotatingFileHandler',
            'filename': 'logs/main_debug.log',
            'maxBytes': 1024 * 1024 * 5,  # 5 MB
            'backupCount': 7,
            'formatter': 'main_formatter',
            'filters': ['require_debug_true'],
        },
        'null': {
            "class": 'django.utils.log.NullHandler',
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['mail_admins', 'console'],
            'level': 'ERROR',
            'propagate': True,
        },
        'django': {
            'handlers': ['null', ],
        },
        'py.warnings': {
            'handlers': ['null', ],
        },
        '': {
            'handlers': ['console', 'production_file', 'debug_file'],
            'level': "DEBUG",
        },
    }
}

文件夹权限

-rw-r--r-- 1 root root 806 May 26 15:36 main.log
-rw-r--r-- 1 root root   0 May 26 15:36 main_debug.log

0 个答案:

没有答案