SQLLoggerMidleware + infobar
This middleware will add a log of the SQL queries executed at the top of every page, in the form of an IE-like 'infobar'. It also includes a query count and total and per-query execution times. This snippet is based on snippet #344 "SQL Log Middleware + duplicates" by guettli. I did some adjustments to the code, to also add support for the application/xhtml+xml mime type, aswell as add the code for the infobar. Need DEBUG on, aswell as DEBUG_SQL, should not be used on production sites. It also expects a 16x16 png image called infobar_icon.png, which it is looking for in the /media/images folder (or /static/images, depending on your MEDIA_URL setting). I used a little light bulb icon from the Tango icon set, but am unable to attach the image. Any 16x16 png will do off course. Update 0.1.1: In the initial version of this middleware, the path to /media/images was hard-coded, and you had to adjust this middleware accordingly. Now, it correctly uses the MEDIA_URL setting from your settings.py file, so you no longer have to edit this middleware. 0.1.2: Made some adjustments to the CSS to get rid of a padding bug when the bar was displayed on a Django error page. Also if a page contains no queries, it won't bother printing an 'empty' table, with just column headers. 0.1.3: More tweaks to the CSS, odd/even row shading on queries table. 0.1.4: More CSS tweaks again 0.1.5: Minor tweaks 0.1.6: Sorry, I just realised that after some time, this snippet broke in the latest SVN of Django with a Unicode error, as arthur78 mentioned. I have managed to fix it, by wrapping line 258 and 259 in an str() function.
- sql
- middleware
- logger