Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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!

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