On 22Apr2015 10:50, Chris Angelico <ros...@gmail.com> wrote:
On Wed, Apr 22, 2015 at 10:11 AM, Cameron Simpson <c...@zip.com.au> wrote:
I have a context manager named "Pfx" which I use liberally in my code like
this:
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.
Cheers,
Cameron Simpson <c...@zip.com.au>
I fit in my suit, my suit fits in my suitcase, hence i fit in my suitcase.
- Cees Keyer <c...@htsa.hva.nl>
--
https://mail.python.org/mailman/listinfo/python-list