Skip to content

Instantly share code, notes, and snippets.

@neilkod
Created November 30, 2011 14:32
Show Gist options
  • Save neilkod/1409254 to your computer and use it in GitHub Desktop.
Save neilkod/1409254 to your computer and use it in GitHub Desktop.
how do i log to both stdout and to a file?
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.
@cd34
Copy link

cd34 commented Nov 30, 2011

@neilkod
Copy link
Author

neilkod commented Nov 30, 2011

I followed my original tweet up with the very same link! I'm good now - thanks!

@cd34
Copy link

cd34 commented Nov 30, 2011

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