Skip to content

Instantly share code, notes, and snippets.

@hgdeoro
Created August 13, 2012 04:07
Show Gist options
  • Save hgdeoro/3336861 to your computer and use it in GitHub Desktop.
Save hgdeoro/3336861 to your computer and use it in GitHub Desktop.
Python logging handler, to notify errors to the desktop
# -*- coding: utf-8 -*-
import logging
import subprocess
class CustomHandler(logging.Handler):
def __init__(self, *args, **kwargs):
logging.Handler.__init__(self, *args, **kwargs)
def emit(self, record):
subprocess.call(["notify-send", "-u", "critical", "ERROR", record.getMessage()])
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'default',
},
'gnome_notify': {
'level': 'WARN',
'class': 'gnome_notify_logging_handler.CustomHandler',
},
},
'formatters': {
'default': {
'format': '[%(levelname)s] [%(asctime)s] %(message)s',
}
},
'loggers': {
'': {
'handlers': ['console', 'gnome_notify'],
'level': 'INFO',
'propagate': True,
},
'django.request': {
'handlers': ['console'],
'level': 'ERROR',
'propagate': True,
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment