Commits

Josh VanderLinden committed d34c69d

Adding some logging

Comments (0)

Files changed (1)

zedify/weechat.py

 #!/usr/bin/env python2
 
+import logging
+import os
 import time
 
 import zmq
 
 
 __author__ = 'codekoala'
-__version__ = '0.0.5'
+__version__ = '0.0.6'
 __descr__ = 'Deliver message notifications to remote machines'
 
 weechat.register('zedifier', __author__, __version__, 'GPL3',
 
 ctx = zmq.Context()
 
+logging.basicConfig(
+    format='%(asctime)s %(levelname)s %(message)s',
+    filename=os.path.expanduser('~/.zedifier.log'),
+    filemode='a',
+    level=logging.DEBUG
+)
+
 
 def buffer_name(buf):
     name = get(buf, 'short_name') or get(buf, 'name')
     }
 
     def __init__(self):
+        self.log = logging.getLogger('zedifier')
         self.configure()
         self.last_msg = None
         self.last_time = None
         weechat.hook_signal('input_text_changed', 'typing', '')
         weechat.hook_signal('buffer_switch', 'buffer_switch', '')
         weechat.hook_signal('window_switch', 'window_switch', '')
-        #weechat.hook_config('plugins.var.python.tray_notify.host',
-        #                    'connect', '')
 
     def configure(self):
         """Update the default configuration options"""
     def connect(self):
         """Connect to services"""
 
+        spec = config.zedifier.push
         if self.mode == MODE_LOCAL:
-            self.pub.bind(config.zedifier.pub)
+            self.log.info('Publishing to {}'.format(spec))
+            self.pub.bind(spec)
         else:
-            self.pub.connect(config.zedifier.push)
+            self.log.info('Pushing to {}'.format(spec))
+            self.pub.connect(spec)
 
     def notify(self, data, buf, date, tags, displayed, hilight, prefix, msg):
         """Send a message notification"""
 
         return OK
 
-    def send(self, obj):
+    def send(self, payload):
         """
         Only send the message if it's changed or been more than 15 seconds
         since the last message.
 
         now = time.time()
 
-        if obj != self.last_msg or \
+        if payload != self.last_msg or \
                 self.last_time is None or \
                 now - self.last_time > 15:
-            self.pub.send_json(obj)
 
-        self.last_msg = obj
+            self.log.debug('Sending: {}'.format(payload))
+            self.pub.send_json(payload)
+
+        self.last_msg = payload
         self.last_time = now
 
     def close(self):