Is there existing code to log-with-bells-on for runtime algorithm diagnostics?

Ian Kelly ian.g.kelly at
Tue Apr 21 21:29:17 CEST 2015

On Tue, Apr 21, 2015 at 1:02 PM, Rob Clewley <rob.clewley at> wrote:
> I don't think the built-in logger is sophisticated enough for this,
> being a flat record of freeform text AFAIU, but the API looks
> appealing.

It doesn't have to be a flat record. You can write a custom a Handler
that does anything you want with the LogRecord, e.g. writing
structured data to a relational database. With logging filters, you
could set that up either in addition to or in place of the standard
flatfile logging.

> I want to be able to insert commands inside of the loops that log
> certain variable states, completed stages of the algorithm (assume
> it's hierarchical), text warnings, and possibly even 'pointers' to
> graphical output objects of some of the intermediate data (e.g.
> matplotlib object handles for lines, points). Then I can trace the
> work done afterwards or step through the process in an IDE debugger
> and make interactive calls to access recent steps, plot certain
> relationships in the current state, etc. The basic logger's "levels"
> of output don't really apply here. I at least want categories, if not
> hierarchical sub-categories.

You might want to also take a look at LoggerAdapters, which let you
add additional contextual data to the LogRecord. You could potentially
use that to define whatever sort of categorization you want.

More information about the Python-list mailing list