Twisted log rotation by size / having an upper limit on the total number of files?

家住魔仙堡 提交于 2019-12-07 10:51:45

问题


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:


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>


来源:https://stackoverflow.com/questions/30706609/twisted-log-rotation-by-size-having-an-upper-limit-on-the-total-number-of-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!