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. ChrisA -- https://mail.python.org/mailman/listinfo/python-list