32

Could you please help me, whats wrong.

import logging

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

And I can't run it, I've got an error:

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

Thank you very much.

FrUh
  • 545
  • 1
  • 4
  • 7

2 Answers2

55

logging.INFO denotes an integer constant with value of 20

INFO Confirmation that things are working as expected.

What you need is logging.info

logging.info("test")
karthikr
  • 97,368
  • 26
  • 197
  • 188
  • 3
    thank you very much, I was using it in my previuos project and I was wondering why it doesn't work. AND I DID NOT NOTICE the LOWER CASE. Ah. – FrUh Aug 17 '13 at 19:38
  • 1
    my god man, this has been the source of so much frustration for me. – alphazwest Jan 28 '20 at 18:20
11

You are trying to call logging.INFO, which is an integer constant denoting one of the pre-defined logging levels:

>>> import logging
>>> logging.INFO
20
>>> type(logging.INFO)
<type 'int'>

You probably wanted to use the logging.info() function (note, all lowercase) instead:

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

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • thank you very much, I was using it in my previuos project and I was wondering why it doesn't work. AND I DID NOT NOTICE the LOWER CASE. Ah. – FrUh Aug 17 '13 at 19:39
  • And you did not notice the CAPS LOCK either, by the looks of it. :-P (And sorry, you can only mark *one* answer as accepted, thanks for the brief acceptance though!) – Martijn Pieters Aug 17 '13 at 19:57