Skip to content

Instantly share code, notes, and snippets.

@calebmadrigal
Created June 18, 2015 18:10
Show Gist options
  • Save calebmadrigal/8e42e3c0f9d9f6c32cdf to your computer and use it in GitHub Desktop.
Save calebmadrigal/8e42e3c0f9d9f6c32cdf to your computer and use it in GitHub Desktop.
Basic python logging example
import logging
config = { 'logfile': 'log_example.log', 'loglevel': 'DEBUG' }
logger = logging.getLogger('log_example')
log_handler = logging.FileHandler(config['logfile'])
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
log_handler.setFormatter(formatter)
logger.addHandler(log_handler)
logger.setLevel(logging.getLevelName(config['loglevel']))
logger.debug('Debug statement; uninteresting... until it is.')
logger.info('This is for informational purposes only: {}'.format('ya'))
logger.warning('This is your last warning')
logger.error('A cubic millimeter of prevention is worth a giga-frikin-joule of cure')
logger.critical("It's over now fool!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment