Search code examples
pythonpython-3.xloggingtypeerror

TypeError: 'int' object is not callable in Python 3 when calling logging.INFO


I am getting TypeError: 'int' object is not callable after passing an object to my class with appropriate arguments.

Is this an issue with logging or class? Can Anyone help me with this?

Following is the Snippet:

import logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s-%(message)s')

class employee:

    def __init__(self,first,last):
        self.first=first
        self.last=last

        logging.INFO('Employee created: {} - {} '.format(self.fullname, self.email))

    @property
    def email(self):
        return '{}.{}@email.com'.format(self.first,self.last)
    @property
    def fullname(self):
        return '{} {}'.format(self.first,self.last)

emp_1=employee('John','Doe')
emp_2=employee('John','Smith')

Solution

  • logging.INFO is a numeric value representing a logging level, it is actually the int 20.

    The method to log an INFO message is logging.info, notice the lowercase.

    logging.info(msg)