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 trialElizabeth McInerney
3,175 PointsLogging
The assignment is to log a message with a level of DEBUG, using any message I want to use. This code returned the error "X Bummer! No DEBUG log messages
import logging
logging.basicConfig(filename='cc.log', level=logging.DEBUG)
# Write your code below here
logging.info("I hope this works")
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsChange the method to .debug()
:
# Write your code below here
logging.debug("I hope this works") #<--- changed method
# This also works:
logging.log(logging.DEBUG, "debug THIS!")
There are two levels at work here. logging.level
is the threshold to determine whether to display a message:
"CRITICAL" > "ERROR" > "WARNING" > "INFO" > "DEBUG". Once a level is set, then each method .debug()
, .info()
will only display if the logging.level
is low enough.
These levels are represented as integers:
In [251]: logging.DEBUG
Out[251]: 10
In [249]: logging.getLogger().getEffectiveLevel()
Out[249]: 10
Elizabeth McInerney
3,175 PointsOk, that worked, but I am going to have to object to this question! According to the video, logging.info logs a message that the specified level, and the level has already been set to DEBUG. So it seems like my code should have worked. Also, there was no point in the video where Kenneth used logging.level(), so the student is not even made aware that this is possible. Not fair!
Chris Freeman
Treehouse Moderator 68,441 Pointsupdated my answer to include alternatives.
Elizabeth McInerney
3,175 PointsElizabeth McInerney
3,175 PointsThanks for all of you help. Your comments above are too deep for me at this point. I just wanted to point out that the video did not give the info necessary to pass the challenge. I also think it flagged my code as not working when maybe it just wasn't written as expected. 2 issues that will have more people posting questions to the Forum than necessary if they were resolved. But I do appreciate the help from you and the course in general!