Twisted log rotation by size / having an upper lim

2019-05-07 06:22发布

I have a twisted server that generates log files and rotates them based on size. If the file size of a particular file is more than 1MB, a new log file is created.

However, after several days of running, the log files start filling up my hard disk.

Is there a way to have an overall limit on log rotation? The limit could be based on total size (like only 200GB worth of logs - anything more would be deleted), or on the number of files (like only 1000 logs would be stored).

1条回答
倾城 Initia
2楼-- · 2019-05-07 06:50

You can use the option logger. You will have to write your own logger factory, something like this

#in module mymodule, file <log.py>
def my_logger():
    f = logfile.LogFile("twistd_alert.log", '/var/log/', rotateLength=1000000, maxRotatedFiles=100)
    log_observer = log.FileLogObserver(f)
    return log_observer.emit

Then while running the server you can specify the option logger as

twistd --logger=mymodule.log.logger <your_server>
查看更多
登录 后发表回答