Difference between Logging and Print in Python

Logging in Python

Print in Python

Record events and errors that occur during the execution of Python programs. Displays the information to the console for the debugging purposes.
Mainly used in the production environment. Mainly for debugging.
Some features are: Log levels, filtering, formatting, and more. There are no good features.
It provides different log levels such as Debug, Info, Error, Warning, and Critical. It does not have any levels, it simply prints whatever is passed to it.

Example:

import logging; 
logging.basicConfig(level=logging.INFO); 
logging.info(“Hello”)

Output:

Can be configured to log to different output destinations (e.g. console, file, network)

Example:

print(“Hello”)

Output:

Prints only on the console



Difference between Logging and Print in Python

In Python, print and logging can be used for displaying information, but they serve different purposes. In this article, we will learn what is python logging with some examples and differences between logging and print in Python.

Similar Reads

Logging in Python

Logging in Python is a technique to display useful messages and warnings to users. The logging module provides a flexible way to log different messages in various output destinations such as on the console, in files, and on networks. Logging is a best practice for production code. The logging module provides features such as log levels and filtering....

Print in Python

...

Difference between Logging and Print in Python

...