[Tutor] Purging/deleting the logfile with the logging module

Kent Johnson kent37 at tds.net
Wed Jan 31 04:00:38 CET 2007


Tony Cappellini wrote:
> 
> 
> I want to purge (empty) or delete the logfile created by the logging 
> module, and reopen it for a new session.
> 
> There is reference to a close function in the 2.3 docs, but I don't see 
> how I can purge or delete the file, since I don't have access to the 
> file descriptor.
> 
> *close*( 	)
> 
>     Tidy up any resources used by the handler. This version does nothing
>     and is intended to be implemented by subclasses. 
> 
> How can I purge/delete & reopen the logfile?

FileHandler has a close() method that presumably does something useful. 
So I guess you have to get ahold of the FileHandler. One way to do that 
would be to configure the logging in code instead of in a config file or 
basicConfig(). There is an example of doing this with a SocketHandler here:
http://docs.python.org/lib/network-logging.html

The code to set up a FileHandler would be very similar.

Kent



More information about the Tutor mailing list