info() method of Logger class in Python

info() logs a message of severity level logging.INFO. into system.err. Through optional parameters exception and stack information can be added to the message.

Logger Updated 24 Mar 2017 1 min read

Method Name

info

Method Signature

info(logMessage, *args, **kwargs)

Method Overview

  • info() method is used to log messages of severity level logging.INFO.

  • Informational log messages may not be error messages all the time.

  • logging.INFO could be used inside a python program to reflect the program state over various time points of its execution

  • For example Authentication succeeded, Session started, Session ended are all informational messages and reflect the program state and the state of the associated entities like user, session and so on.

  • The optional parameters of info() method args and kwargs are explained as part of the debug() method of logger class.

Example

python
import logging

def PythonFunction():

    # Set the standard log prefix

    formatString = '%(asctime)s %(filename)s Function:%(funcName)s() %(message)s'

    # Set the log level - to logging.INFO and above

    logging.basicConfig(level=logging.INFO, format=formatString)

    # Get a logger object with this module name

    loggerObject = logging.getLogger(__name__)

    # Start logging

    loggerObject.info("This is an info message")

PythonFunction()

Output

Output
2017-03-24 18:32:43,189 info.py Function:PythonFunction() This is an info message