Created
November 30, 2011 14:32
-
-
Save neilkod/1409254 to your computer and use it in GitHub Desktop.
how do i log to both stdout and to a file?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bash-3.1$ cat logging_with_date.py | |
import logging | |
logging_format = '%(asctime)s %(levelname)s:%(message)s' | |
logging.basicConfig(format=logging_format, filename = 'myprogram.log', level=logging.DEBUG) | |
logging.debug('is when %s event was logged.', 'out of memory') | |
logging.warning('is when %s event was logged.', 'out of memory') | |
logging.info('is when %s event was logged.', 'out of memory') | |
logging.critical('is when %s event was logged.', 'out of memory') | |
bash-3.1$ python logging_with_date.py | |
bash-3.1$ cat myprogram.log | |
2011-11-30 06:31:27,387 DEBUG:is when out of memory event was logged. | |
2011-11-30 06:31:27,387 WARNING:is when out of memory event was logged. | |
2011-11-30 06:31:27,388 INFO:is when out of memory event was logged. | |
2011-11-30 06:31:27,388 CRITICAL:is when out of memory event was logged. |
I followed my original tweet up with the very same link! I'm good now - thanks!
Came up in Google reader for me - I don't really check twitter much - once a week if that which makes it really difficult since scrolling back through more than a day or so of tweets is a pain.
I've thought about making a tweet logger just to keep up since I don't check frequently enough.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://docs.python.org/dev/howto/logging-cookbook.html#logging-to-multiple-destinations