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 trial

Python Write Better Python Buggy Logs Log Messages

Log a message with a level of DEBUG. The message can say anything you want.

Watched video several times, not sure where to go from here. =) please help

starter.py
import logging

logging.basicConfig(filename='cc.log', level=logging.DEBUG)

# Write your code below here
state = 7
logging.info('state')

6 Answers

task 1

import logging

logging.basicConfig(filename='cc.log', level=logging.DEBUG)

Write your code below here

logging.debug('This message should go to the log file')

hope this help, truly not in the video found docs python.org

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

At 5:03, we log a message with logging.info() and I bring up that .debug(), .warn(), etc all log messages at those levels. We also did logging.warn() and logging.info() before that. So, no, we didn't do exactly logging.debug() but if you were following along, it shouldn't have been that big of a jump to do.

Sorry if it was confusing!

Piotr Manczak
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Piotr Manczak
Front End Web Development Techdegree Graduate 29,324 Points

Thanks for your time and effort. I watched video many times and spend a lot of time trying different stuff without succes. Luckly, you are with us. Thanks again.

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

The prompt says to create a log message at level debug. You did logging.info() which creates a message at level info.

Jose Luis Lopez
Jose Luis Lopez
19,179 Points

import logging

logging.basicConfig(filename='cc.log', level=logging.DEBUG) logging.debug("yes")

This is how this code worked for me since I used logging.info and didn't let me pass the task

I see, my thinking was that logging.info would log all levels, including DEBUG. I made the code work with logging.debug. Thanks again Kenneth, that would be radical to work together on a future project. I am also a Oregon Python-artista. =)

task 2

import logging

logging.basicConfig(filename='cc.log', level=logging.DEBUG)

Write your code below here

logging.debug('This message should go to the log file') logging.warning("The French have the Grail" )

Logging works based on the level that you set and acts as the threshold for tracking events. Levels in order of severity from lowest to highest - debug, info, warning, error, critical.

Example #1:

logging.basicConfig(filename='cc.log', level=logging.DEBUG) 
logging.debug('Debug message')
logging.info('Info message')
logging.warning('Warning Message')

will write all these messages to the cc.log file, since DEBUG is the lowest level

DEBUG:root:Debug message                                                                                                       
INFO:root:Info message                                                                                                         
WARNING:root:Warning Message 

Example #2:

logging.basicConfig(filename='logger.log', level=logging.ERROR)
logging.error('Error message')
logging.critical('Critical message')
logging.warning('Warning Message') 

will exclude the warning message

ERROR:root:Error message                                                                                                       
CRITICAL:root:Critical message