Logging

Logging is very useful for a programmer at debugging side. It will keep track of the logs/operations performed during the program.

Python provides the standard library to perform logging. You can get the information, debug the program, generate warning or error.

We will see the very useful use case of logging in decorators.

So, by considering the example taken in the decorators we are going to discuss logging.

Using logging, we can keep track of what arguments executed

Creating a function with arguments to be passed in a decorator function

In this calculating the office hours, we are keeping track of what variables are used by using logging functionality in the outer function.

Created another function without arguments to be passed in the decorator function.

After running these two function when we will check our log file created by using “config” command, will be created in the same directory and stores the log as -:

Log file(company_log_file.log) contains these outputs -:

Hope you are clear with the logging concepts. Stay tuned! Keep learning with us.

Close Menu