Created
January 10, 2017 05:09
-
-
Save chroming/e64f0cbc7004384c2006b3eb11d090a9 to your computer and use it in GitHub Desktop.
python logging记录日志
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 | |
logging.basicConfig(filename='%s.log' % today, level=logging.INFO, format='TIME: %(asctime)s -- LEVEL:%(levelname)s -- MESSAGE: %(message)s', datefmt='[%d/%b/%Y %H:%M:%S]') | |
# 同时在日志文件和控制台记录日志 | |
console = logging.StreamHandler() | |
console.setLevel(logging.INFO) | |
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s') | |
console.setFormatter(formatter) | |
logging.getLogger('').addHandler(console) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment