-
-
Save robcowie/1388961 to your computer and use it in GitHub Desktop.
Growl (GNTP) logging handler
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
"""Growl (GNTP) logging handler""" | |
import logging | |
import gntp.notifier | |
class GrowlHandler(logging.Handler): | |
"""Log messages to growl""" | |
def __init__(self, level=logging.NOTSET): | |
logging.Handler.__init__(self, level) | |
self.formatter = logging.Formatter( | |
'%(asctime)s - %(name)s - %(levelname)s - %(message)s', | |
datefmt='%H:%M:%S') | |
self.growl = gntp.notifier.GrowlNotifier( | |
applicationName="My Application Name", | |
notifications=["DEBUG", "ERROR", "CRITICAL"], | |
defaultNotifications=["New Messages"], | |
hostname="127.0.0.1", | |
password="" | |
) | |
self.growl.register() | |
def emit(self, record): | |
""" """ | |
self.growl.notify( | |
noteType=record.levelname, | |
title="Log %s" % record.levelname, | |
description=self.format(record), | |
sticky=False, | |
priority=1, | |
) | |
if __name__ == '__main__': | |
log = logging.getLogger('test') | |
handler = GrowlHandler(level=logging.DEBUG) | |
log.addHandler(handler) | |
log.setLevel(logging.DEBUG) | |
log.debug("Y'all wanna park at my house?") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment