Commit aec9fcfe authored by Luci Stanescu's avatar Luci Stanescu

Made logging more robust at application exit

parent 2b32fb83
......@@ -58,6 +58,8 @@ class Blink(QApplication):
self.update_manager.shutdown()
self.application.stop()
self.application.thread.join()
log_manager = LogManager()
log_manager.stop()
def customEvent(self, event):
handler = getattr(self, '_EH_%s' % event.name, Null)
......@@ -83,10 +85,6 @@ class Blink(QApplication):
self.main_window.show()
self.update_manager.initialize()
def _NH_SIPApplicationDidEnd(self, notification):
log_manager = LogManager()
log_manager.stop()
def _initialize_sipsimple(self):
notification_center = NotificationCenter()
notification_center.add_observer(self, sender=self.application)
......
......@@ -2,11 +2,14 @@
# This module will be replaced by an improved logging system. -Luci
#
from __future__ import with_statement
__all__ = ['LogManager']
import os
import sys
from datetime import datetime
from threading import RLock
from application import log
from application.notification import IObserver, NotificationCenter
......@@ -72,6 +75,7 @@ class LogManager(object):
self.pjsiptrace_file = Null
self.notifications_file = Null
self.event_queue = EventQueue(handler=self._process_notification, name='Log handling')
self._lock = Null
self._siptrace_start_time = None
self._siptrace_packet_count = None
......@@ -87,24 +91,30 @@ class LogManager(object):
self.pjsiptrace_file = LogFile(os.path.join(ApplicationData.directory, 'logs', 'pjsip_trace.txt'))
if settings.logs.trace_notifications:
self.notifications_file = LogFile(os.path.join(ApplicationData.directory, 'logs', 'notifications_trace.txt'))
self._lock = RLock()
self._siptrace_start_time = datetime.now()
self._siptrace_packet_count = 0
self.event_queue.start()
def stop(self):
self.event_queue.stop()
self.event_queue.join()
notification_center = NotificationCenter()
notification_center.remove_observer(self)
with self._lock:
event_queue = self.event_queue
self.event_queue = Null
event_queue.stop()
self._lock = Null
event_queue.join()
self.siptrace_file = Null
self.msrptrace_file = Null
self.pjsiptrace_file = Null
self.notifications_file = Null
notification_center = NotificationCenter()
notification_center.remove_observer(self)
def handle_notification(self, notification):
self.event_queue.put(notification)
with self._lock:
self.event_queue.put(notification)
def _process_notification(self, notification):
handler = getattr(self, '_NH_%s' % notification.name, Null)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment