Quick Contact

    Python Tutorial
    Python Panda Tutorial
    Python Selenium
    Python Flask Tutorial
    Python Django
    Numpy
    Tensorflow
    Interview Questions & Answers

    Django Logging

    What is Logging?

    Logging is a technique or medium which can let us track some events as the software executes. It is an important technique for developers. It helps them to track events. Logging is like an extra set of eyes for them. Developers are not only responsible for making software but also for maintaining them.

    Logging helps with that part of maintenance immensely.

    It tracks every event that occurs at all times. That means instead of the long tracebacks you get much more. This time when an error occurs you can see in which the system was. This method will help you resolve errors quickly.

    Logging Working

    The logging is handled by a separate program. That logging program is simply a file-writer. The logger is said to record certain events in text format. The recorded information is then saved in files. The files for this are called logs.

    The logs are simple files saved with log extension. They contain the logs of events occurred.

    Logging Module in Python

    The logging module is a built-in Python module. It comes preinstalled with Python 3. Logging module is used to keep track of the events that occur as the program runs. That can be extended to any number of programs and thus for software, it is easy to set up and use.

    Why use logging module?

    All logging does is writing to a file or printing it on the console. All that can be achieved by using print statements.

    We use print function to output something on console. So, when a function occurs, we can get a print statement that the function executed. While that approach works with smaller applications, it is inefficient.

    Print function becomes part of your program and if the software stops working, you won’t get the result.

    The logging module is capable of:

    • Multithreading execution
    • Categorizing Messages via different log levels
    • It’s much more flexible and configurable
    • Gives a more structured information

    Loggers

    The loggers are the objects that developers deal with. They can be understood as a function which will be invoked when they are called. We use loggers in our project files. Thus, when the function is invoked, we get a detailed report. The logger can generate multiple levels of responses.

    Handlers

    Handlers are the objects which emit the information. Think of them as newspaper handlers. Their main task is to transmit the information. That can be achieved by writing the info in a log file (The default behaviour). There are various handlers provided by logging module.

    We can easily set-up multiple handlers for the same logger. There are SMTP Handlers too which will mail the log records to you.

    Formatters

    The formatters are the ones which format the data. You see handlers cannot send the information as it’s a Python data type.

    The logs are by-default in Log Records format. That is the class pre-defined by logging framework. It gives various methods to developers to use.

    Filters

    The last piece of the logging module is filters. The filters, as the name suggests, filter the messages. Not every message we pass needs to be stored or transported. Or there can be different handlers for different messages. All that is achievable with the help of filters.

    We can use filters with both loggers and handlers.

    It also provides us with message levels. The message levels are defined as:

    • DEBUG:

      It is verbose system information when everything is running fine. It will tell you more precise details about the state of the system. Its severity point is 10.

    • INFO:

      The info will produce less verbose system information but is similar to debug. It generally tells an overview of what the system is executing. Its severity point is 20.

    • WARNING:

      This contains information regarding low-level problems. The problems may be ignored as they don’t cause the system to halt. Although, it is recommended that these problems shall be resolved.

    • Its severity point is 30.
    • ERROR:

      This message is serious. The error will contain information about the major problem that has occurred. The problem may have stopped the operation of program and needs immediate attention.

    • CRITICAL:

      The most critical message. This message is emitted when the problem has caused the system to stop. That means the whole application has halted due to this problem.


     

     

    Apply now for Advanced Python Training Course

    Copyright 1999- Ducat Creative, All rights reserved.

    Anda bisa mendapatkan server slot online resmi dan terpercaya tentu saja di sini. Sebagai salah satu provider yang menyediakan banyak pilihan permainan.