Created
August 13, 2012 04:07
-
-
Save hgdeoro/3336861 to your computer and use it in GitHub Desktop.
Python logging handler, to notify errors to the desktop
This file contains 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
# -*- 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()]) |
This file contains 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
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