关于调试:Python logging typeerror

Python logging typeerror

你能帮帮我吗,怎么了?

1
2
3
4
5
import logging

if (__name__ =="__main__"):
    logging.basicConfig(format='[%(asctime)s] %(levelname)s::%(module)s::%(funcName)s() %(message)s', level=logging.DEBUG)
    logging.INFO("test")

我不能运行它,我有一个错误:

1
2
3
4
Traceback (most recent call last):
  File"/home/htfuws/Programming/Python/just-kidding/main.py", line 5, in
    logging.INFO("test")
TypeError: 'int' object is not callable

非常感谢你。


logging.INFO表示值为20的整数常数。

INFO Confirmation that things are working as expected.

你需要的是logging.INFO

1
logging.info("test")


您试图调用logging.INFO,它是一个整数常量,表示预定义的日志级别之一:

1
2
3
4
5
>>> import logging
>>> logging.INFO
20
>>> type(logging.INFO)
<type 'int'>

您可能想使用logging.info()函数(注意,全部小写)来代替:

Logs a message with level INFO on this logger. The arguments are interpreted as for debug().