Skip to content

Instantly share code, notes, and snippets.

@paul-schwendenman
Last active January 21, 2016 04:05
Show Gist options
  • Save paul-schwendenman/9a63e4352010aa67bcb5 to your computer and use it in GitHub Desktop.
Save paul-schwendenman/9a63e4352010aa67bcb5 to your computer and use it in GitHub Desktop.
'''
Logging Example
'''
import logging
def main():
'''
Main
'''
log_file = 'test.log'
logging.basicConfig(filename=log_file,
format='%(asctime)s - %(levelname)s - %(message)s',
level=logging.DEBUG)
logger = logging.getLogger('')
logger.debug('log line debug')
logger.info('log line info')
logger.warning('log line warning')
logger.error('log line error!')
logger.critical('log line critical')
def main2():
'''
Main
'''
# log_file = 'test.log'
stream = logging.StreamHandler()
log_file = logging.FileHandler('tst.log')
logging.basicConfig(handlers=(log_file, stream),
format='%(asctime)s - %(levelname)s - %(message)s',
level=logging.DEBUG)
logger = logging.getLogger('')
logger.debug('log line debug')
logger.info('log line info')
logger.warning('log line warning')
logger.error('log line error!')
logger.critical('log line critical')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment