【发布时间】:2019-07-08 16:54:43
【问题描述】:
我需要在调试时显示日志消息,我应该如何使用如下代码显示消息:
logs.out("Here are the error messages")
logs.clear()
【问题讨论】:
标签: error-logging
我需要在调试时显示日志消息,我应该如何使用如下代码显示消息:
logs.out("Here are the error messages")
logs.clear()
【问题讨论】:
标签: error-logging
您应该使用日志库, 这是一个例子:
import logging
logging.debug('debug message')
logging.info('information message')
logging.warning('A warning message')
logging.error('Error Description')
logging.critical('Critical messages should be here')
【讨论】:
如果您希望只输出一些常用文本进行日志记录,那么您可以选择 Python 的 print() 函数,或者您希望以正确的方式进行日志记录,那么您可以使用 logging API由 Python 本身作为库提供。
`
import logging
logging.basicConfig(filename='example.log', level=logging.debug)
logging.debug("Debugging")
`
【讨论】: