You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »


1. Python

1.1. Initialisation

Logger is a static  member of a class. Suggested name is "logger" . An example:

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

1.2. 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')

1.3. Setting logging level

Logging levels

# LOGGING LEVELS:

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


User can configure logging level for:

  • all classes of given application (via root logger)

    import logging
    
    # setting ALL loggers
    logging.basicConfig(level=logging.ERROR)
  • given class (via class logger ) 

    import logging 
    
    #setting particular logger
    logging.getLogger(A.B.__qualname__).setLevel(logging.INFO)





  • No labels