text
Are you a Professional Python Developer? Here is why Logging is important for debugging, tracking and monitoring the code
Are you a Professional Python Developer? Here is why Logging is important for debugging, tracking and monitoring the code
new_line
new_line
text
Logging
Logging
new_line
text
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. 
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. 
new_line
new_line
text
Basic Logging Setup
Basic Logging Setup
new_line
text
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.
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.
new_line
new_line
text
Here is how we can use basic console logging
Here is how we can use basic console logging
new_line
code_fence
```
#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 since we did not added filename to save logs
logging.debug('Here we go for debug message')
logging.info('Here we go for info message')
logging.warning('Here we go for warning message')
logging.error('Here we go for error message')
logging.critical('Here we go for critical message')

#Note:
# If you want to add anything in the log then do like this way
records=100
logging.debug('There are total %s number of records.', records)

# same like string format 
lost=20
logging.debug('There are total %s number of records from which %s are lost', records, lost)
```
#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 since we did not added filename to save logs
logging.debug('Here we go for debug message')
logging.info('Here we go for info message')
logging.warning('Here we go for warning message')
logging.error('Here we go for error message')
logging.critical('Here we go for critical message')

#Note:
# If you want to add anything in the log then do like this way
records=100
logging.debug('There are total %s number of records.', records)

# same like string format 
lost=20
logging.debug('There are total %s number of records from which %s are lost', records, lost)
new_line
new_line
new_line
text
Logging to a File
Logging to a File
new_line
text
We can also save the log to a file instead of console. For this, we can add the filename parameter to logging.basicConfig().
We can also save the log to a file instead of console. For this, we can add the filename parameter to logging.basicConfig().
new_line
new_line
code_fence
```
import logging
# Saving the log to a file. The logs will be written to app.log
logging.basicConfig(filename='app.log', level=logging.DEBUG)

logging.debug('Here we go for debug message')
logging.info('Here we go for info message')
logging.warning('Here we go for warning message')
logging.error('Here we go for error message')
logging.critical('Here we go for critical message')
```
import logging
# Saving the log to a file. The logs will be written to app.log
logging.basicConfig(filename='app.log', level=logging.DEBUG)

logging.debug('Here we go for debug message')
logging.info('Here we go for info message')
logging.warning('Here we go for warning message')
logging.error('Here we go for error message')
logging.critical('Here we go for critical message')
new_line
text
You can read more on my medium blog 
You can read more on my medium blog 
link
https://medium.com/@imranzaman-5202/are-you-a-professional-python-developer-8596e2b2edaa
https://medium.com/@imranzaman-5202/are-you-a-professional-python-developer-8596e2b2edaa
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. 

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 since we did not added filename to save logs
logging.debug('Here we go for debug message')
logging.info('Here we go for info message')
logging.warning('Here we go for warning message')
logging.error('Here we go for error message')
logging.critical('Here we go for critical message')

#Note:
# If you want to add anything in the log then do like this way
records=100
logging.debug('There are total %s number of records.', records)

# same like string format 
lost=20
logging.debug('There are total %s number of records from which %s are lost', records, lost)
```


Logging to a File
We can also save the log to a file instead of console. For this, we can add the filename parameter to logging.basicConfig().

```
import logging
# Saving the log to a file. The logs will be written to app.log
logging.basicConfig(filename='app.log', level=logging.DEBUG)

logging.debug('Here we go for debug message')
logging.info('Here we go for info message')
logging.warning('Here we go for warning message')
logging.error('Here we go for error message')
logging.critical('Here we go for critical message')
```
You can read more on my medium blog https://medium.com/@imranzaman-5202/are-you-a-professional-python-developer-8596e2b2edaa
👀
John6666 bkhalid063 AtAndDev wing0night