Created
May 8, 2017 00:07
-
-
Save gwding/276353c2150968d6fc70eac20c3d3618 to your computer and use it in GitHub Desktop.
quick example of how to let logging output to a file and stdout
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 to file and stdout at the same time""" | |
import logging | |
import sys | |
def config_logging(filename='example.log', format="%(message)s"): | |
logging.basicConfig( | |
filename=filename, | |
format=format, | |
level=logging.DEBUG) | |
root = logging.getLogger() | |
root.setLevel(logging.DEBUG) | |
ch = logging.StreamHandler(sys.stdout) | |
ch.setLevel(logging.DEBUG) | |
root.addHandler(ch) | |
config_logging() | |
logging.info("info") | |
logging.debug('debug') | |
logging.info('info') | |
logging.warning('warning') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment