Created
September 23, 2009 22:03
-
-
Save vsajip/192335 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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