Last active
December 10, 2015 11:59
-
-
Save c0ldlimit/4431530 to your computer and use it in GitHub Desktop.
#python using logging module
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
| # http://docs.python.org/release/2.3.5/lib/node304.html | |
| # http://www.blog.pythonlibrary.org/2012/08/02/python-101-an-intro-to-logging/ | |
| import logging | |
| logger = logging.getLogger('myapp') | |
| hdlr = logging.FileHandler('/var/tmp/myapp.log') | |
| formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') | |
| hdlr.setFormatter(formatter) | |
| logger.addHandler(hdlr) | |
| logger.setLevel(logging.WARNING) | |
| We can use this logger object now to write entries to the log file: | |
| logger.error('We have a problem') | |
| logger.info('While this is just chatty') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment