Skip to content

Instantly share code, notes, and snippets.

@simonw
Created October 11, 2009 02:25
Show Gist options
  • Select an option

  • Save simonw/207346 to your computer and use it in GitHub Desktop.

Select an option

Save simonw/207346 to your computer and use it in GitHub Desktop.
# 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