Skip to content

Instantly share code, notes, and snippets.

@c0ldlimit
Last active December 10, 2015 11:59
Show Gist options
  • Select an option

  • Save c0ldlimit/4431530 to your computer and use it in GitHub Desktop.

Select an option

Save c0ldlimit/4431530 to your computer and use it in GitHub Desktop.
#python using logging module
# 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