[IPython-dev] Configuring logging for the kernel?

Fernando Perez fperez.net at gmail.com
Mon Feb 14 03:36:19 EST 2011


Howdy,

I've merged:

https://github.com/ipython/ipython/pull/264

after Omar took Robert's feedback into account.  But I'm not very
experienced with the logging module, so I'm wondering what the best
pattern should be for enabling logging conveniently at the
command-line level.  Right now, applications like the Qt console have
to pass flags to the kernel (and there's some duplication there we
should remove, like the code in ipythonqt.py and entry_point that
creates the parsers).  We can pass a --log-level flag to the kernel
entry point script easily, that's not a problem.

My question has to do with how to cleanly and conveniently let the
kernel log to the screen or a file, keeping in mind that the kernel
will be running in a separate process.  The default approach to
configuring logging for libraries is to let the application using a
library set its own handlers, but in this case the app (say a Qt
console) is calling the kernel in another process, so it can't pass it
any handlers; in fact it can't pass the kernel anything other than
command-line flags.

The code path is somewhat elaborate, because options have to pass from
the user-facing client through the kernel manager and ultimately to
the actual kernel object (in ipkernel.py).  I admit I played with it
for a while and got a bit lost, so I'm looking for some ideas on this
one.  In addition, we need to keep in mind that all of the Qt console
code is still in need of a Configurable restructuring, but that can be
handled separately from this.

If anyone for now needs to re-activate message printing to debug
low-level kernel behavior, this snippet in ipkernel.py, below the
logger definition line, will do:

logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.DEBUG)

But what I want to do is come up with a cleaner solution for the long run...

Cheers,

f



More information about the IPython-dev mailing list