[SciPy-User] Is there existing code to log-with-bells-on for runtime algorithm diagnostics?
cs at zip.com.au
Wed Apr 22 03:21:50 CEST 2015
On 22Apr2015 10:50, Chris Angelico <rosuav at gmail.com> wrote:
>On Wed, Apr 22, 2015 at 10:11 AM, Cameron Simpson <cs at zip.com.au> wrote:
>> I have a context manager named "Pfx" which I use liberally in my code like
>> from cs.logutils import Pfx, info
>> def load(filename):
>> with Pfx("loading %r", filename):
>> with open(filename) as fp:
>> lineno = 0
>> for line in fp:
>> lineno += 1
>> with Pfx("%d", lineno):
>> ... do stuff with line ...
>> info("line value is foo=%r", foo)
>> This causes the info() call to report like this:
>> loading 'myfile.dat': 21: line value is foo=12345
>Very nice! I'm guessing it depends on the use of info(), though,
>rather than applying to pre-existing logging calls? Even so, all that
>means is that you use a specific call to do your logging, and
>everything works perfectly. The nesting is excellent.
Well, yes; there's a small suite of wrappers in the cs.logging module. But you
can hook them up to various outputs via the core logging stuff. The exception
catch/reraise is also very useful - orthoganal to the logging.
It is in PyPI, BTW.
Cameron Simpson <cs at zip.com.au>
I fit in my suit, my suit fits in my suitcase, hence i fit in my suitcase.
- Cees Keyer <cees at htsa.hva.nl>
More information about the Python-list