Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

like image 956
Utkarsh Sinha Avatar asked Mar 16 '23 19:03

Utkarsh Sinha


1 Answers

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>
like image 126
Dark Light Avatar answered Apr 08 '23 16:04

Dark Light