Python

Initialisation

Class "static" member

Logger should be defined as a static  member of a class. Suggested name is "logger" . An example:

import logging
 
class B:
        # class logger 
        logger = logging.getLogger(__name__ + "." +__qualname__)


A global variable

Logger can be defined as a global variable  (i.e. out of a class scope).  This is not recommended way , because names may clash, if two or more modules will use the same name of variable. 


import logging

# global variable 
logger = logging.getLogger(__name__)

class B:
		# class content
		pass     

Printing information

The recommended way to access logger from within a class  is __class__.logger 

__class__.logger.debug('This is a debug message')
__class__.logger.info('This is an info message')
__class__.logger.warning('This is a warning message')
__class__.logger.error('This is an error message')
__class__.logging.critical('This is a critical message')

Setting logging level

# LOGGING LEVELS:

  • logging.DEBUG
  • logging.INFO
  • logging.WARNING
  • logging.ERROR
  • logging.CRITICAL


User can configure logging level for: