代码如下:
import logging # 日志类简单应用,方便规范格式化输出日志 def t(): for i in range(10): logging.info("print %s",i) logging.error('发送错误') if __name__ == '__main__': logging.basicConfig(level=logging.INFO,format='%(asctime)s - %(levelname)s: %(message)s') t()
输出如下:
2023-08-05 22:21:58,818 - INFO: print 0 2023-08-05 22:21:58,818 - INFO: print 1 2023-08-05 22:21:58,818 - INFO: print 2 2023-08-05 22:21:58,818 - INFO: print 3 2023-08-05 22:21:58,818 - INFO: print 4 2023-08-05 22:21:58,818 - INFO: print 5 2023-08-05 22:21:58,818 - INFO: print 6 2023-08-05 22:21:58,818 - INFO: print 7 2023-08-05 22:21:58,818 - INFO: print 8 2023-08-05 22:21:58,818 - INFO: print 9 2023-08-05 22:21:58,818 - ERROR: 发送错误
标签:21,22,05,11python,08,818,应用,print,日志 From: https://www.cnblogs.com/chenzhi2023/p/17608793.html