SENSSOFT-73 #implemented exit handler
diff --git a/userale/ale.py b/userale/ale.py
index 6aac603..6ddf474 100644
--- a/userale/ale.py
+++ b/userale/ale.py
@@ -20,7 +20,7 @@
 import datetime, time
 import logging
 import uuid
-import json
+import atexit
 
 _ = JsonFormatter
 
@@ -122,7 +122,7 @@
         # self.timer2 = QTimer ()
         # self.timer2.timeout.connect (self.sample2)
         # self.timer2.start (0)
-
+        #self.destroyed.connect (Ale._on_destroyed)
         # Batch transmission of logs
         self.intervalID = self.startTimer (self.interval)
 
@@ -130,6 +130,9 @@
         self.logs = []
         self.hlogs = []
 
+        # Register Exit hanldler
+        atexit.register (self.cleanup)
+
     def eventFilter (self, object, event):
         '''
         :param object: [QObject] The object being watched.
@@ -166,6 +169,13 @@
 
         return super (Ale, self).eventFilter (object, event)
 
+    def cleanup (self):
+        '''
+        Clean up any dangling logs in self.logs or self.hlogs
+        '''
+        self.aggregate ()
+        self.dump ()
+
     def timerEvent (self, event):
         '''
         :param object: [list] List of events
@@ -173,8 +183,11 @@
 
         Routinely dump data to file or send over the network
         '''
+        self.dump ()
+
+    def dump (self):
         if len(self.logs) > 0:
-            #print ("dumping {} logs".format (len (self.logs)))
+            # print ("dumping {} logs".format (len (self.logs)))
             self.logger.info (_(self.logs))
             self.logs = [] # Reset logs
 
@@ -184,7 +197,7 @@
         to be emitted later
         '''
         if len (self.hlogs) > 0:
-            #print ("agging {} logs".format (len (self.hlogs)))
+            # print ("agging {} logs".format (len (self.hlogs)))
             agg_events = Counter (self.hlogs)
             # Iterate over collapsed collection to generate a single log per event
             # Location information is lost due to consolidation.