[Matt Whiteley wrote] > All, > > I need to limit the size of a log file I'm creating. At the moment, I'm just > appending to it and it's going >100MB which is a bit excessive. > > I'd like the file to 'roll' so the first entries get pushed out as the later > entries come in. > > Are there any pre-written examples of this, or is there a simple way to do > it please ?
There are a few ways you could do this. You could os.stat the log file's size every once in a while (one every write? though that might be slow) and if the file passes a threshold size you could: - close the file handle - os.rename(<logfile>, <logfile>+<timestamp>) - open(<logfile>) Or you could roll over the file once per day (or per hour, etc). I don't know of any pre-written examples of doing this although you might want to ask on [EMAIL PROTECTED] Cheers, Trent p.s. There is a current proposal to add a standard logging module to Python 2.3 which will very likely provide a standard way of doing this for you. http://www.python.org/peps/pep-0282.html -- Trent Mick [EMAIL PROTECTED] _______________________________________________ ActivePython mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs