Pages

Sunday, November 4, 2012

python logging

Python logging lets the information is shown to the screen, or written to a file. Without any file setup, the default action is to print out the info to the screen.

You have three levels of logging: debug > info > warning. The strongest level is debug, and the weakest is warning.
import logging

logging.warning('Watch out!') # will print a message to the console
logging.info('I told you so') # will not print anything
You can use "basicConfig()" method to login the info to the file. For level, if you choose "DEBUG", every debug/info/warning message is logged, with "INFO", only info/waring, and so on.
import logging
logging.basicConfig(filename='example.log',level=logging.DEBUG)

logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')

References

No comments:

Post a Comment