Question on templates and python logging

David LePage dwlepage at
Sat Apr 3 19:42:20 EDT 2010

Hi -
I have been struggling with this problem for quite some time and was hoping somebody could give me some pointers.

I have a wxPython front end wizard that collects some information and outputs some HTML pages (not hosted by a web server, but viewable locally on the machine running the application).

The problem that i'm trying to solve is taking data collected along the way and outputting this into these HTML pages. 

One of the pages is simply collecting debug information about the execution of the program. 
All logging is  currently being done using the python logging library.

Due to the fact that my HTML files need to be populated in the <body> tags, I wanted to write directly to the proper HTML page based on the logging level message (INFO, DEBUG, etc).

Something like this works nicely if you have a dictionary storing the data:

def template():
  return open("html/html.tmpl", 'r').read() % vars
print template("html/Logs.html", { 'body' : "A test body field" })

But in my case, some of the data could be MB in size and I didn't want to read/write that entire load of data before displaying the pages if at all possible. 
I was hoping I could tie the logging classes into something like this, where I was leveraging an HTML template, but also taking advantage of the logging library since it works nicely for me today.

Does anybody have any suggestions on how they might approach this problem?




More information about the Python-list mailing list