0% found this document useful (0 votes)
12 views3 pages

pdf&rendition=1-3

Helpful for coding

Uploaded by

Rajath S Kashyap
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)
12 views3 pages

pdf&rendition=1-3

Helpful for coding

Uploaded by

Rajath S Kashyap
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/ 3

What is logging explain with factorial program and explain the different levels of logging

Logging is a great way to understand what’s happening in your program and in what order it’s
happening

To enable the logging module to display log messages on your screen as your program runs, copy
the following to the top of your program

when Python logs an event, it creates a LogRecord object that holds information about that event

The logging module’s basicConfig() function lets you specify what details about
the LogRecord object you want to see and how you want those details displayed.

The factorial of a number. In mathematics, factorial 4 is 1 × 2 × 3 × 4, or 24. Factorial 7 is 1 × 2 × 3


× 4 × 5 × 6 × 7, or 5,040

Here, we use the logging.debug() function when we want to print log information

This debug() function will call basicConfig(), and a line of information will be printed.
The print(factorial(5)) call is part of the original program, so the result is displayed even if logging
messages are disabled.

The factorial() function is returning 0 as the factorial of 5, which isn’t right.

But the log messages displayed by logging.debug() show that the i variable is starting at 0 instead
of 1.

Change the for i in range(n + 1): line to for i in range(1, n + 1):, and run the program again. The
output will look like this:
Logging Levels
Logging levels provide a way to categorize your log messages by importance.

There are five logging levels, described in Table 11-1 from least to most important.

Messages can be logged at each level using a different logging function.

You might also like