Garth T Kidd wrote:
Strikes me that not much work could let someone keep all of their existing print statements more or less intact and use the logging module properly, too:
import logging
class LoggingHandle: def __init__(self, wrappedmethod): self.wrappedmethod = wrappedmethod def write(self, msg): msg = msg.rstrip() if msg: self.wrappedmethod(msg.rstrip())
logging.basicConfig() log = logging.getLogger('whatever') stderr = LoggingHandle(log.error) stdout = LoggingHandle(log.info)
print >> stdout, "This is informational." # logged as INFO print >> stderr, "This is an error." # guess.
Add some basic infrastructure to logging, and you're done. The Extremely Brave could even alter sys.stderr and sys.stdout.
Main purpose of logging module is not redirection, but filtering capability. -- Best regards, Michael Dubner (dubnerm@mindless.com) Brainbench MVP/HTML+JavaScript (http://www.brainbench.com) PS: Sorry for my English