Logging helps you to keep track of the program/application you run. It stores the outputs/errors/messages/exceptions anything you want to store. Program executions can be debugged with the help of print statements during the runtime of code. But the code is not elegant and not a good practice. Logging is a standard process an application to follow to store the process in a log file that would help to analyze/debug in the future/unexpected situations.
Logging for exceptions
For a logger, we have different levels of logging a message. As the article is limited to exception logging, we will go with the ‘INFO’ level log message which helps us to check if the code is working as expected. If there is an exception, it will store exception into the log file using logger object logger.exception(“some exception raised”)
Below is the implementation.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | Raising an Exception to Another Exception
- Python | Add Logging to a Python Script
- Python | Add Logging to Python Libraries
- Logging in Python
- Python | Logging Test Output to a File
- Python VLC Instance - Unsetting Logging Callbacks
- Class as decorator in python
- Data Classes in Python | Set 2 (Decorator Parameters)
- Decorator Method - Python Design Patterns
- call() decorator in Python
- Python Property Decorator - @property
- Dispatch Decorator in Python
- Implementing LRU Cache Decorator in Python
- Decorator to print Function call details in Python
- Creating Decorator inside a class in Python
- Context Manager Using @contextmanager Decorator
- Python Exception Handling
- Multiple Exception Handling in Python
- Python | Reraise the Last Exception and Issue Warning
- How to pass argument to an Exception in Python?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.