Skip to content

Instantly share code, notes, and snippets.

@minimal
Created November 23, 2011 15:14
Show Gist options
  • Save minimal/1388924 to your computer and use it in GitHub Desktop.
Save minimal/1388924 to your computer and use it in GitHub Desktop.
KDE knotify logging handler
"""KDE knotify logging handler"""
import logging
import dbus
class KNotifyHandler(logging.Handler):
"""Log messages to kde notifications"""
def __init__(self, level=logging.NOTSET):
logging.Handler.__init__(self, level)
self.formatter = logging.Formatter(
'%(asctime)s - %(levelname)s - %(message)s',
datefmt='%H:%M:%S')
self.knotify = dbus.SessionBus().get_object("org.kde.knotify",
"/Notify")
def emit(self, record):
""" """
self.knotify.event("warning", "kde", [], record.name,
self.format(record), [], [], 0, 0,
dbus_interface="org.kde.KNotify")
if __name__ == "__main__":
log = logging.getLogger(__name__)
log.addHandler(KNotifyHandler(logging.WARNING))
log.warn("This is a test notification")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment