Does python logging.handlers.RotatingFileHandler allow creation of a group writable log file?

前端 未结 7 566
太阳男子
太阳男子 2021-01-31 08:40

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

相关标签:
7条回答
  • 2021-01-31 09:31

    Here is a slightly better solution. this overrides the _open method that is used. setting the umask before creating then returning it back to what it was.

    class GroupWriteRotatingFileHandler(logging.handlers.RotatingFileHandler):    
        def _open(self):
            prevumask=os.umask(0o002)
            #os.fdopen(os.open('/path/to/file', os.O_WRONLY, 0600))
            rtv=logging.handlers.RotatingFileHandler._open(self)
            os.umask(prevumask)
            return rtv
    
    0 讨论(0)
提交回复
热议问题