Forums

OSError: [Errno 13] Permission denied: '/var/log/listjungle.log.2'

Hi guys,

From time to time I see this error from a scheduled task

Traceback (most recent call last):
  File "/usr/lib/python2.7/logging/handlers.py", line 77, in emit
    self.doRollover()
  File "/usr/lib/python2.7/logging/handlers.py", line 135, in doRollover
    os.remove(dfn)
OSError: [Errno 13] Permission denied: '/var/log/listjungle.log.2'
Logged from file updateposts.py, line 33

In a admin command that I call as a scheduled task I have

import logging
log = logging.getLogger('listjungle')

log.info('UpdatePostsTask started')

and in settings.py I have

LOGGING = {
    'version': 1,
    'disable_existing_loggers': True,
    'formatters': {
        'standard': {
            'format' : "[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s",
            'datefmt' : "%d/%b/%Y %H:%M:%S"
        },
    },
    'handlers': {
        'null': {
            'level':'DEBUG',
            'class':'django.utils.log.NullHandler',
        },
        'logfile': {
            'level':'DEBUG',
            'class':'logging.handlers.RotatingFileHandler',
            'filename': '/var/log/listjungle.log',
            'maxBytes': 50000,
            'backupCount': 2,
            'formatter': 'standard',
        },
        'console':{
            'level':'INFO',
            'class':'logging.StreamHandler',
            'formatter': 'standard'
        },
    },
    'loggers': {
        'django': {
            'handlers':['console'],
            'propagate': True,
            'level':'WARN',
        },
        'django.db.backends': {
            'handlers': ['console'],
            'level': 'DEBUG',
            'propagate': False,
        },
        'listjungle': {
            'handlers': ['console', 'logfile'],
            'level': 'DEBUG',
        },
    }
}

Any suggestions why it happens?

Thank you!

We changed the permissions on the /var/log folder a month or two ago, to avoid a problem with logrotate and people losing access to their files. Users now have read/write access to files, but not read/write access to the folder, which means you cannot delete files or create new files in /var/log.

I tried to email everyone that was using custom log files at the time, but I guess we didn't spot you.

In any case, for "regular" logging, if you just use stderr, we will write stuff out to /var/log/www.yourdomain.error.log for you, and handle log rotation automatically. If you want to do custom logging, you should use the folder /var/log/my-logs, to which you have full read/write access, including adding + deleting files....

I get it, thank you!