Control Log File Size

Matt McCredie mccredie at gmail.com
Fri Oct 19 13:41:29 EDT 2007


> I've got an application running on linux which writes log files using the
> python logging module. I'm looking for some help and advice to cap the size
> which the file will grow too, something reasonably like 2Mb would be great.
>
>
>
> What is the best way to handle this kind of thing? Can this be done using a
> setting in the logging module? Or is it something I'll have to get the FS to
> handle for me?

Check out the RotatingFileHandler: http://docs.python.org/lib/node413.html

It is part of the logging module and should do what you want.

Examples of using alternative handlers are here:

http://docs.python.org/lib/multiple-destinations.html

Matt



More information about the Python-list mailing list