Python logging to file


Here is a simple example for logging with python:

import logging

logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', filename='example.log', level=logging.DEBUG)
logging.debug('This is debug message.')'This is info message.')
logging.warning('This is warning message.')

Output logged in example.log file:

2013-12-31 15:58:10,776 DEBUG This is debug message.
2013-12-31 15:58:10,777 INFO This is info message.
2013-12-31 15:58:10,777 WARNING This is warning message.

Since we used logging level as logging.DEBUG all messages(debug, info, and warning) will logged into our log file(example.log log file I am using).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s