Skip to content

Instantly share code, notes, and snippets.

@vsajip
Created September 23, 2009 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vsajip/192335 to your computer and use it in GitHub Desktop.
Save vsajip/192335 to your computer and use it in GitHub Desktop.
#
# Copyright 2009 Vinay Sajip
#
import logging
logger = logging.getLogger(__name__)
class LogWriter:
def __init__(self, logger):
self.logger = logger
def as_stream(self, levelname):
level = logging.getLevelName(levelname.upper())
logger = self.logger
class StreamProxy:
def write(self, s):
if s != '\n':
logger.log(level, s)
return StreamProxy()
def main():
logging.basicConfig(level=logging.DEBUG)
lw = LogWriter(logger)
info = lw.as_stream('info')
debug = lw.as_stream('debug')
print >> info, 'Info!',
print >> debug, 'Debug!',
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment