Reputation: 3305
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).
Upvotes: 4
Views: 1203
Reputation: 1250
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>
Upvotes: 7