Skip to content

Instantly share code, notes, and snippets.

@chroming
Created January 10, 2017 05:09
Show Gist options
  • Save chroming/e64f0cbc7004384c2006b3eb11d090a9 to your computer and use it in GitHub Desktop.
Save chroming/e64f0cbc7004384c2006b3eb11d090a9 to your computer and use it in GitHub Desktop.
python logging记录日志
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