Rather than a flat ASCII file, you could just use the database of your
choice
(mySql, etc.) and include a sequence #, date, priority, source and comment
fields. You could overwrite based on any field you wanted. You'd need to
write a small tool to make a log report from the database.

Also check out: http://www.red-dove.com/python_logging.html
I'm not sure if it has a max size of logfile option - would have to be a
FileHandler
specific option - maybe you guys should work together in it.
(I also notice there's no DBHandler - maybe my idea was not a good one?)

mike

You could even try a Shelve:

import shelve
class Log: #untested
        MAX = 2**20
        def __init__(self):
                self.size = size.seq = 0
                self.shelf = shelve.open("log.bin")
        def write(self, msg):
                self.size += len(msg)
                if self.size > Log.MAX: self.seq=self.size=0
                self.shelf[seq] = (msg,) # add other stuff to tuple...
                self.seq++
        def __del__(self):
                self.shelf.close()

Then write a little program (about the same size)
to make the log report.

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Trent
Mick
Sent: Friday, April 12, 2002 9:50 AM
To: Matt Whiteley
Cc: [EMAIL PROTECTED]
Subject: Re: Log File Size Limiter


[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

_______________________________________________
ActivePython mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to