On 06Jul2014 15:15, Roy Smith <r...@panix.com> wrote:
In article <mailman.11552.1404673207.18130.python-l...@python.org>,
Mark Lawrence <breamore...@yahoo.co.uk> wrote:
In the 21st century real programmers are using the logging module so
they don't have to mess around.

The problem with the logging module is you can configure it to do pretty
much anything, which is another way of saying if it's not configured
right (perhaps because you're running your application in an environment
it wasn't designed for), your output disappears into the ether.

I can't tell you how many times I've given up fighting with logging and
just done "open("/tmp/x").write("my debugging message\n") when all else
failed.

Indeed. I have a cs.logutils module, which is almost entirely support for the logging module (standard setups, funky use cases), but it also defines two functions, X and D, thus:

    def X(fmt, *args):
      msg = str(fmt)
      if args:
        msg = msg % args
      sys.stderr.write(msg)
      sys.stderr.write("\n")
      sys.stderr.flush()

    def D(fmt, *args):
      ''' Print formatted debug string straight to sys.stderr if D_mode is true,
          bypassing the logging modules entirely.
          A quick'n'dirty debug tool.
      '''
      global D_mode
      if D_mode:
        X(fmt, *args)

I use X() for ad hoc right now debugging and D() for turn on at need debugging.

Surprisingly handy. Many many of my modules have "from cs.logutils import X, D" at the top.

Cheers,
Cameron Simpson <c...@zip.com.au>

"How do you know I'm Mad?" asked Alice.
"You must be," said the Cat, "or you wouldn't have come here."
--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to