Created
October 11, 2009 02:25
-
-
Save simonw/207346 to your computer and use it in GitHub Desktop.
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
| # Python logging handler for stashing most recent 100 log items in a redis list | |
| import logging | |
| import redis | |
| r = redis.Redis() | |
| class RedisLogHandler(logging.Handler): | |
| def emit(self, record): | |
| r.push('python-log', unicode(record).encode("utf8"), tail=True) | |
| # Truncate the list to the last 100 items | |
| r.ltrim('python-log', 0, 99) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment