Random notes from mg

a blog by Marius Gedminas

Marius is a Python hacker. He works for Programmers of Vilnius, a small Python/Zope 3 startup. He has a personal home page at http://gedmin.as. His email is marius@gedmin.as. He does not like spam, but is not afraid of it.

Sat, 07 Aug 2010

Capturing logs with Dozer

Dozer is mostly known for its memory profiling capabilities, but the as-yet unreleased version has more:

Log capturing

This WSGI middleware intercepts logging calls for every request. Here we see a toy Pylons application I've been working on in my spare time. Dozer added an info bar at the top:

Dozer's infobar

When you click on it, you get to see all the log messages produced for this request. I've set SQLAlchemy's loglevel to INFO in my development.ini, which produces:

Dozer's log viewer

(Why on Earth does SQLAlchemy think I want to see the memory address of the Engine object in my log files, I don't know. The parentheses contain argument values for parametrized queries, of which there are none on this page.)

Upstream version displays absolute timestamps (of the YYYY-MM-DD HH:MM:SS.ssssss variety) in the first column; my fork shows deltas in milliseconds. The incantation in development.ini is

use = egg:Dozer#logview
next = main

which makes it disabled by default. To enable, you run paster like this:

$ paster serve development.ini -n logview

(Upstream version lacks the paste entry point for logview; it's in my fork, for which I submitted a pull request weeks ago like a good open-source citizen. Incidentally, patches for stuff I maintain have been known to languish for years in my inbox, so I'm not one to throw stones.)

Next: profiling with Dozer.

Update: Tom Longson blogged about this back in 2008! And his CSS is prettier.

posted at 05:27 | tags: | permanent link to this entry | 5 comments
Very cool.  Me likes.
posted by matt harrison at Sat Aug 7 06:25:50 2010
its so you can distinguish between multiple engines.  the hexish string can be replaced by a name of your choosing using the "logging_name" parameter  (http://www.sqlalchemy.org/docs/reference/sqlalchemy/connections.html#sqlalchemy.create_engine) or of course by configuring a logging formatter yourself (http://www.sqlalchemy.org/docs/dbengine.html#configuring-logging).
posted by mike bayer at Sat Aug 7 08:41:18 2010
This is cool stuff!
Is the styling for the bar at the top configurable? For my project it overlays the navigation, which is a bit bad. I would make it a small thing in the corner and expand full size when clicked.
posted by Florian Schulze at Sat Aug 7 12:46:32 2010
I think the style is hardcoded, but it's not difficult to find it and tweak it in Dozer sources.

I'd love to see Dozer grow into something like Django Debug Toolbar.
posted by Marius Gedminas at Sat Aug 7 17:12:33 2010
You can have colors for specific pylons sources by adding another line to the INI file like so:

logview.sqlalchemy = #faa
logview.pylons.templating = #bfb

Which would color pylons.templating lines with a green color, and sqlalchemy lines with a red. I usually do that to make it easier to see when I accidentally trigger a lazy load after a template started running.
posted by Ben Bangert at Sat Aug 7 21:50:47 2010

Name (required)

E-mail (will not be shown)


Comment (some HTML allowed)