03-Django Adv

Logging Works in Django

Logger

Print statement generally does not work in production so, to get message we use logger

What is Logging?

How Logging Works in Django

  • Django comes with Python's built-in logging module to leverage system logging.
    1. Loggers
    2. Handlers
    3. Filters
    4. Formatters

Loggers

  • Loggers are basically the entry point of the logging system.
  • If the log-level is same or exceeds the log-level of the logger, the message is sent to the handler for further processing.
DEBUG:		     10 --> Low-level system information
INFO:		     20 --> General system information
WARNING:	     30 --> Minor problems related information
ERROR/EXCEPTION: 40 --> Major problems related information
CRITICAL:	     50 --> Critical problems related information
dblogger.debug("Test Debug")

dblogger.info("Test Info")

dblogger.warning("Test Warning")
dblogger.warn("Test Warn")  # Depricated

dblogger.error("Test Error")
dblogger.exception("Test Exception")

dblogger.critical("Test Critical")

Handlers

Handlers basically determine what happens to each message in a logger eg: write to a file or console.

[Read More]