The main infrastructure for having consistent format logging with various levels of severity. It can either be used as a class instance or through the default static functions for simplicity
import logging
logging.setLevel(logging.INFO)
logging.debug("Test debug message 1")
logging.info("Test info message 1")
# will print
# Test info message 1
logging.setLevel(logging.DEBUG)
logging.debug("Test debug message 2")
logging.info("Test info message 2")
# will print
# Test debug message 2
# Test info message 2
logging.setLevel(level)
Sets the logging level which filters the type of messages that will be printed.
logging.debug(msg, *args)
Print DEBUG message
logging.info(msg, *args)
Print INFO message
logging.error(msg, *args)
Print ERROR message
logging.exception(e, msg, *args)
Print EXCEPTION message along with the stack trace provided by e
instance.
except
statementlogging.Logger(name)
Create an instance of a Logger with name.
Logger.log(level, msg, *args, **kwargs)
The main logging method that actually constructs and prints the message
Logger.debug(self, msg, *args, **kwargs)
Shorthand call of Logger.log with DEBUG level.
Logger.info(self, msg, *args, **kwargs)
Shorthand call of Logger.log with INFO level.
Logger.warning(self, msg, *args, **kwargs)
Shorthand call of Logger.log with WARNING level.
Logger.error(self, msg, *args, **kwargs)
Shorthand call of Logger.log with ERROR level.
Logger.critical(self, msg, *args, **kwargs)
Shorthand call of Logger.log with CRITICAL level.
Logger.exc(self, e, msg, *args)
Shorthand call of Logger.log with EXCEPTION level. An exception instance must be provided.
Logger.exception(self, msg, *args)
Shorthand call of Logger.log with EXCEPTION level. Queries sys.exc_info for details on the exception.