Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.