I\'m using the standard python (2.5.2) logging module, specifically the RotatingFileHandler
, on a linux system. My application supports both a command-line interfa
It looks that def _open(self):
worked with umask(0o000)
to get all the permissions of -rw-rw-rw-
.
os.chmod(self.baseFilename, 0o0777)
failed with ValueError: Unable to configure handler 'some_handler': [Errno 1] Operation not permitted:
if the log file has ownership of root:root
that's different from running process's, such as testuser
.
from logging import handlers
import logging
import os
class GroupWriteRotatingFileHandler(handlers.RotatingFileHandler):
def _open(self):
prevumask = os.umask(0o000) # -rw-rw-rw-
rtv = logging.handlers.RotatingFileHandler._open(self)
os.umask(prevumask)
return rtv
LOGGING = {
'handlers': {
'db_handler': {
'level': 'DEBUG',
'class': 'log.GroupWriteRotatingFileHandler',
'filename': PATH_TO_LOGS + '/db.log',
'maxBytes': maxBytes,
'backupCount': backupCount,
'formatter': 'standard',
},
Log files:
logs]# ls -lrt
-rw-rw-rw- 1 root root 71 Apr 1 16:02 db.log
logs]# ls -lrt
total 0
-rw-rw-rw- 1 testuser testuser 0 Apr 1 16:20 db.log