Modifying a built-in function for logging purposes

Greg Krohn greg at invalid.invalid
Sat May 14 16:29:31 EDT 2005


qwweeeit at yahoo.it wrote:
> Hi all,
> I wonder if it is possible to change (temporarily) a built-in function
> for logging purposes.
> Let me explain:
> I want to log all the 'open' operations, recording the file to be
> opened, the "mode" (r/w/a...) and (possibly) the module which made the
> call.
> After that the 'open' can carry on following the standard built-in
> path.
> Possibly I don't want to have to modify the source of the application
> to be logged.
> If there is another solution, I am open to any suggestion...
> 
> Bye.
> 

Would this work?

_file = file
def file(path, mode):
     print path, mode
     return _file(path, mode)

-greg



More information about the Python-list mailing list