Last active
January 21, 2016 04:05
-
-
Save paul-schwendenman/9a63e4352010aa67bcb5 to your computer and use it in GitHub Desktop.
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
''' | |
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