Skip to content

Instantly share code, notes, and snippets.

@xjoker
Last active September 8, 2016 03:38
Show Gist options
  • Save xjoker/48252ec11bf835dfcebb301fd7d699c5 to your computer and use it in GitHub Desktop.
Save xjoker/48252ec11bf835dfcebb301fd7d699c5 to your computer and use it in GitHub Desktop.
python 日志模块
import logging
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(filename)s[Line:%(lineno)d] %(levelname)s %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
filename='SSDB_SERVER.log',
filemode='w')
console = logging.StreamHandler()
console.setLevel(logging.INFO)
formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')
console.setFormatter(formatter)
logging.getLogger('').addHandler(console)
# 输出范例
# 2016-09-08 11:34:23 api_refresh_service.py[Line:29] INFO 刷新服务启动
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment