Warning() method of logger class

Method Name:

warning

 

Method Signature:

warning(logMessage, *args, **kwargs)

 

Method Overview:

  • warning() method is used to log messages of severity level logging.WARNING.

 

  • The warning log messages may or may not point to something wrong, but generally set the tone that some event has happened against the normal course.

 

  • Examples for warning messages include resource depletion such as disk space usage reaching a high threshold, CPU temperature reaching the maximum threshold, password strength is low and so on.

 

  • Note that logging.WARNING is the default log level set in a Python Environment

 

  • The log message is composed of several parameters taken from *args and **kwargs as explained in the debug() method of logger class.

 

Example:

import logging

 

logr = logging.getLogger(__name__)

print("Log level-numeric code:")

print(logr.getEffectiveLevel())

 

# Set a standard log prefix

formatString = '%(asctime)s %(filename)s => %(message)s'

logging.basicConfig(format=formatString)

 

logr.warning("A sample warning message")

 

Output:

Log level-numeric code:

30

2017-03-25 03:19:34,954 logr3.py => A sample warning message


Copyright 2024 © pythontic.com