Python, want logging with log rotation and compression

后端 未结 9 1171
暖寄归人
暖寄归人 2020-11-28 01:43

Can anyone suggest a way in python to do logging with:

  • log rotation every day
  • compression of logs when they\'re rotated
  • optional - delete old
9条回答
  •  青春惊慌失措
    2020-11-28 02:24

    Here is my solution(modified from evgenek), simple and does not block python code while gzipping huge log files:

    class GZipRotator:
        def __call__(self, source, dest):
            os.rename(source, dest)
            subprocess.Popen(['gzip', dest])
    

提交回复
热议问题