Logging实战操作
Logging实战操作
#coding=utf-8
import requests
import logging
logging.basicConfig(
level=logging.INFO,
filename='runlog.log',
format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s')
logging.info('start login')
base_url = "http://127.0.0.1:8000/groups/"
auth = ("hudechao","hdc@328216")
param = {"name":"group_1"}
r = requests.post(base_url, auth=auth, data=param)
logging.info('end get')
查看日志文件runlog.log
2019-07-28 11:03:11,938 test_hdc.py[line:9] INFO start login
2019-07-28 11:03:12,058 test_hdc.py[line:14] INFO end get