Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBrian Pitts
Courses Plus Student 3,826 Pointslogging levels and hierarchy of accessible messages
Does one set the basicConfig level to the minimum level you want messages to appear at. In other words, setting WARNING does not allow DEBUG as shown below since DEBUG appears before WARNING in the message chain. Am I understanding this correctly?
import logging
logging.basicConfig(filename='cc.log', level=logging.WARNING)
logging.debug("My logged message")
logging.warning("The French have the Grail")
cc.log:
WARNING:root:The French have the Grail
VERSUS
import logging
logging.basicConfig(filename='cc.log', level=logging.DEBUG)
logging.debug("My logged message")
logging.warning("The French have the Grail")
cc.log:
DEBUG:root:My logged message
WARNING:root:The French have the Grail
setting the level of logging seems to define which messages can be generated. Above we see that setting a WARNING level does not allow "DEBUG" to appear in the log file.
1 Answer
jcorum
71,830 PointsHere's an excerpt from the video transcript (with timestamps):
What does level mean?
3:31
Well, level tells the logger what level to start paying attention to,
3:37
for messages, it'll ignore any messages with a lower level.
3:42
Well, what levels are available?
3:46
Well, there are six log levels and
3:47
their names make it pretty obvious what they're for.
3:49
They're critical, error, warning, info, debug, and notset.
Brian Pitts
Courses Plus Student 3,826 PointsBrian Pitts
Courses Plus Student 3,826 PointsI see now but didn't hear then. Thanks.
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 Pointsfor referring to the transcripts!