Use logging in python script(quick note)

Python(tested in 2.7) logging module can be used for logging in a file or printing on the screen while running the script or scheduling it  via cron.

1.Write in a file.

import logging

logging.basicConfig(filename='/your/log/file', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')

response='<some execution output>'

logging.debug(response)

logging.debug("This is a sample log")

2.Print on screen

import logging

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')

response='<some execution output>'

logging.debug(response)

logging.debug("This is a sample log")

For more information visit:

http://inventwithpython.com/blog/2012/04/06/stop-using-print-for-debugging-a-5-minute-quickstart-guide-to-pythons-logging-module/