0% found this document useful (0 votes)
0 views2 pages

Logging in Python

Logging in Python is essential for tracking events during software execution, aiding in debugging and problem detection. Unlike print statements, which are not effective for complex scripts, Python's built-in logging module provides structured logging with various levels of severity. The document outlines the different logging levels and their corresponding numeric values, emphasizing the importance of logging for maintaining software reliability.

Uploaded by

Sumadhur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views2 pages

Logging in Python

Logging in Python is essential for tracking events during software execution, aiding in debugging and problem detection. Unlike print statements, which are not effective for complex scripts, Python's built-in logging module provides structured logging with various levels of severity. The document outlines the different logging levels and their corresponding numeric values, emphasizing the importance of logging for maintaining software reliability.

Uploaded by

Sumadhur
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Logging in Python

Last Updated: 02 Aug, 2024

Logging is a means of tracking events that happen when some software runs. Logging is important for

software developing, debugging, and running. If you don't have any logging record and your program

crashes, there are very few chances that you detect the cause of the problem. And if you detect the cause, it

will consume a lot of time. With logging, you can leave a trail of breadcrumbs so that if something goes

wrong, we can determine the cause of the problem.

There are a number of situations like if you are expecting an integer, you have been given a float and you can

a cloud API, the service is down for maintenance, and much more. Such problems are out of control and are

hard to determine.

Why print statement is not Pythonic

Some developers use the concept of printing the statements to validate if the statements are executed

correctly or if some error has occurred. But printing is not a good idea. It may solve your issues for simple

scripts but for complex scripts, the printing approach will fail.

Python has a built-in module logging which allows writing status messages to a file or any other output

streams. The file can contain information on which part of the code is executed and what problems have

arisen.

Python Logging Levels

- Debug: Used to give detailed information, typically of interest only when diagnosing problems.

- Info: Used to confirm that things are working as expected.

- Warning: Used as an indication that something unexpected happened, or is indicative of some problem in
Logging in Python

the near future.

- Error: Indicates a more serious problem; the software has not been able to perform some function.

- Critical: Tells serious error, indicating that the program itself may be unable to continue running.

Logging Level Numeric Values

Level Numeric Value

NOTSET 0

DEBUG 10

INFO 20

WARNING 30

ERROR 40

CRITICAL 50

You might also like