Created
June 18, 2015 18:10
-
-
Save calebmadrigal/8e42e3c0f9d9f6c32cdf to your computer and use it in GitHub Desktop.
Basic python logging example
This file contains 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
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