debug() method of logger class

debug() method logs a message with severity of logging.DEBUG to the stderr. Based on the optional parameter passed debug prints exception and stack information

Logger Updated 24 Mar 2017 1 min read

Method Name

debug

Method Signature

debug(logMessage, *args, **kwargs)

Method Overview

  • debug() method is used to log messages of severity level logging.DEBUG.

Parameters

logMessge: The message to be logged. To be precise it is the log message

format, since several arguments can be added to it customizing

each log message using the *args and **kwargs parameters

*args: The arguments that can be added to the logMessage using Python string

formatting. *args in Python is used to pass arbitrary number of unnamed arguments.

**kwargs: **kwargs in Python is used to pass arbitrary number of named

arguments or keyword arguments. The debug() method supports 3 named parameters:

They are exc_info, stack_info, and extra.

The exc_info argument is used to add the exception information if any to be added to the log message. To add exception information to the log message the exc_info paramter should evaluate to True.

stack_info argument is used to add the stack information to the log message. To add stack information to the log message the stack_info parameter should evaluate to True.

Example

python
import logging

# Set the standard log prefix
formatString = '%(asctime)s %(message)s'

# Set the log level - to DEBUG and above
logging.basicConfig(level=logging.DEBUG, format=formatString)

# Get a logger object with this module name
loggerObject = logging.getLogger(__name__)

# Start logging
loggerObject.debug("This is a debug message")

##

Output

Output
2017-03-24 17:26:19,322 This is a debug message

##