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

前端 未结 7 576
太阳男子
太阳男子 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:04

    Here is a simple solution worked fine:

    import os
    
    class GroupWriteRotatingFileHandler(handlers.RotatingFileHandler):
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            os.chmod(self.baseFilename, 0o0777)  # You can change whatever permission you want here.
    
            # you can also change the group of the file:
            os.chown(self.baseFilename, uid, gid)   # pass the user_id and group_id you want to set 
    
    

提交回复
热议问题