Skip to content

Instantly share code, notes, and snippets.

@robcowie
Forked from minimal/knotify_log.py
Created November 23, 2011 15:28
Show Gist options
  • Save robcowie/1388961 to your computer and use it in GitHub Desktop.
Save robcowie/1388961 to your computer and use it in GitHub Desktop.
Growl (GNTP) logging handler
"""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