[Python-Dev] Guidelines for Logging Usage (original) (raw)

Michael P. Dubner dubnerm-news at mail.ru
Tue Oct 5 08🔞18 CEST 2004


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 at mindless.com) Brainbench MVP/HTML+JavaScript (http://www.brainbench.com) PS: Sorry for my English



More information about the Python-Dev mailing list