logging.debug("This is DEBUG !!") logging.info("This is INFO !!")w logging.warning("This is WARNING !!") logging.error("This is ERROR !!") logging.critical("This is CRITICAL !!")
try: 3/0 except Exception as e: # logging.error(e) logging.exception(e)
输出日志如下:
1 2 3 4 5 6 7 8 9 10 11
2021-03-26 02:03:01 - root - DEBUG - basiclogging : 16 line - This is DEBUG !! 2021-03-26 02:03:01 - root - INFO - basiclogging : 17 line - This is INFO !! 2021-03-26 02:03:01 - root - WARNING - basiclogging : 18 line - This is WARNING !! 2021-03-26 02:03:01 - root - ERROR - basiclogging : 19 line - This is ERROR !! 2021-03-26 02:03:01 - root - CRITICAL - basiclogging : 20 line - This is CRITICAL !!
2021-03-26 03:16:47 - root - ERROR - basiclogging : 27 line - division by zero Traceback (most recent call last): File "E:/pycharm_project/examples-of-web-crawlers-master/logginng/basiclogging", line 24, in <module> 3/0 ZeroDivisionError: division by zero