Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python logging typeerror

Tags:

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.

like image 817
FrUh Avatar asked Aug 17 '13 19:08

FrUh


People also ask

How do I enable logging in Python?

You can configure logging as shown above using the module and class functions or by creating a config file or a dictionary and loading it using fileConfig() or dictConfig() respectively. These are useful in case you want to change your logging configuration in a running application.

What is logging error in Python?

Logging an exception in python with an error can be done in the logging. exception() method. This function logs a message with level ERROR on this logger. The arguments are interpreted as for debug(). Exception info is added to the logging message.

What is logging getLogger (__ Name __)?

To start logging using the Python logging module, the factory function logging. getLogger(name) is typically executed. The getLogger() function accepts a single argument - the logger's name. It returns a reference to a logger instance with the specified name if provided, or root if not.

What is logging package in Python?

Python comes with a logging module in the standard library that provides a flexible framework for emitting log messages from Python programs. This module is widely used by libraries and is the first go-to point for most developers when it comes to logging.


2 Answers

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") 
like image 142
karthikr Avatar answered Sep 21 '22 12:09

karthikr


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().

like image 28
Martijn Pieters Avatar answered Sep 22 '22 12:09

Martijn Pieters