Created
January 23, 2014 03:58
-
-
Save hxu/8572587 to your computer and use it in GitHub Desktop.
Generic python logger setup
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 | |
logger = logging.getLogger('log') | |
logger.setLevel(logging.DEBUG) | |
log_formatter = logging.Formatter('%(asctime)s - %(module)s - %(levelname)s - %(message)s', | |
datefmt='%Y-%m-%d %H:%M:%S') | |
# Log to file | |
logfile = logging.FileHandler('run.log') | |
logfile.setLevel(logging.DEBUG) | |
logfile.setFormatter(log_formatter) | |
# Log to console | |
logstream = logging.StreamHandler() | |
logstream.setLevel(logging.INFO) | |
logstream.setFormatter(log_formatter) | |
logger.addHandler(logfile) | |
logger.addHandler(logstream) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment