Created
November 23, 2011 15:14
-
-
Save minimal/1388924 to your computer and use it in GitHub Desktop.
KDE knotify 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
"""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