Python代码
1 2 3 4 5 6 7 8 9 10 11
| import logging LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s" DATE_FORMAT = "%m/%d/%Y %H:%M:%S %p" logging.basicConfig(filename='apiStudy.log', level=logging.DEBUG, format=LOG_FORMAT, datefmt=DATE_FORMAT)
def test(): print("test") logging.info("这是一个info log") logging.error("这是一个error log") logging.debug("这是一个debug log") logging.warn("这是一个warn log")
|
最终显示效果
1 2 3 4 5 6 7 8 9 10 11
| 12/26/2019 10:01:23 AM - DEBUG - Starting new HTTPS connection (1): www.aqistudy.cn:443 12/26/2019 10:01:23 AM - DEBUG - https://www.aqistudy.cn:443 "GET /historydata/ HTTP/1.1" 200 None 12/26/2019 10:02:40 AM - DEBUG - Starting new HTTPS connection (1): www.aqistudy.cn:443 12/26/2019 10:02:40 AM - DEBUG - https://www.aqistudy.cn:443 "GET /historydata/ HTTP/1.1" 200 None 12/26/2019 10:03:28 AM - DEBUG - Starting new HTTPS connection (1): www.aqistudy.cn:443 12/26/2019 10:03:28 AM - DEBUG - https://www.aqistudy.cn:443 "POST /historydata/api/historyapi.php HTTP/1.1" 200 None 12/26/2019 12:11:19 PM - DEBUG - Starting new HTTPS connection (1): www.aqistudy.cn:443 12/26/2019 12:11:28 PM - DEBUG - https://www.aqistudy.cn:443 "POST /historydata/api/historyapi.php HTTP/1.1" 200 None 12/26/2019 12:12:57 PM - DEBUG - Starting new HTTPS connection (1): www.aqistudy.cn:443 12/26/2019 12:12:59 PM - DEBUG - https://www.aqistudy.cn:443 "POST /historydata/api/historyapi.php HTTP/1.1" 200 None 12/26/2019 12:15:17 PM - DEBUG - Starting new HTTPS connection (1): www.aqistudy.cn:443
|
写在最后
欢迎大家关注鄙人的公众号【麦田里的守望者zhg】,让我们一起成长,谢谢。