如何在Python中显示日志消息

时间:2019-07-08 16:54:43

标签: error-logging

我需要在调试时显示日志消息,该怎么做才能用以下代码显示消息:

logs.out("Here are the error messages")
logs.clear()

2 个答案:

答案 0 :(得分:1)

您应该使用日志记录库, 这是一个示例:

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')

答案 1 :(得分:0)

如果您只想输出一些常见的文本进行记录,则可以选择使用Python的print()函数,否则,您可以选择像应该记录日志一样正确的方式进行记录,则可以使用{{ 1}}由Python本身作为库提供的API。

`

logging

`