python的日志

2021-06-21 14:21:36 浏览数 (1)

一.教程

  1. import logging
  2. logging.basicConfig(level=logging.DEBUG, format=' %(asctime)s - %(levelname)s
  3. - %(message)s') #filename='myProgramLog.txt'  可以指定输入文件
  4. logging.debug('Some debugging details.') #发送日志
  5. logging.disable(logging.CRITICAL) #禁止

二.实例

  1. import logging
  2. logging.basicConfig(level=logging.DEBUG, format=' %(asctime)s - %(levelname)s- %(message)s')
  3. logging.debug('Start of program')
  4. def factorial(n):
  5.     logging.debug('Start of factorial(%s%%)' % (n))
  6.     total = 1
  7. for i in range(1, n 1):
  8.         total = total * i
  9.         logging.debug('i is ' str(i) ', total is ' str(total))
  10.     logging.debug('End of factorial(%s%%)' % (n))
  11. return total
  12. print(factorial(7))
  13. logging.debug('End of program')

三.日志级别

0 人点赞