Reputation: 10081
I have a program where I want to record the function name, parameters passed to the function and the result. I am currently recording this using a decorator. However I am unsure how to store this. Currently I am just appending to a file each time.
I want to just be able to add my decorators to any function in any python program and record the result. As such I need to be able to store the data with each time. This makes it difficult to use XML to store the data as the document would have to be parsed, added to and rewritten each time.
Any suggestions on how I can save this information?
Upvotes: 3
Views: 414
Reputation: 940
wrap all those inside a class and then use pickle module
I have a project that do something very close to what you want: coopy
Upvotes: 3
Reputation: 273386
Use the logging
module from the standard library. It is designed to provide a flexible framework for logging information from a running application (across modules and source files).
In particular, it supports the notion of handlers, allowing you to send logging information into various sinks: files, sockets, email, syslog daemon (on Unix) and so on. If neither of the existing handlers answers your needs, it isn't difficult to write a custom one and plug it in. For instance, you can implement a logger that writes into a database.
Upvotes: 2