Info() method of Logger class in Python

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:

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:

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

 

         

          


Copyright 2024 © pythontic.com