Member-only story
Are you a Professional Python Developer? Here is why Logging is important for debugging, tracking and monitoring the code
Logging
Logging is very important part of any project you start. It help you to track the execution of a program, debug issues, monitor system performance and keep an audit trail of events. It is python built-in logging
module and it provides a flexible framework for adding logging.
We will be discussing the following things:
Basic logging configuration.
Logging to a single file from multiple Python files.
Logging to separate files from each Python file.
Customizing log formats.
Best practices for logging.
1. Basic Logging Setup
The basic way to add logging to a Python code is by using the logging.basicConfig()
function. This function set up basic configuration for logging messages to either console or to a file.
Here is how we can use basic console logging
#Call built in library
import logging
# lets call library and start logging
logging.basicConfig(level=logging.DEBUG) #you can add more format specifier
# It will show on the console…