Commit b703b4f6 authored by Tijmen de Mes's avatar Tijmen de Mes

Added message trace/logging

parent 3fd96387
...@@ -53,6 +53,7 @@ class GoogleContactsSettings(SettingsGroup): ...@@ -53,6 +53,7 @@ class GoogleContactsSettings(SettingsGroup):
class LogsSettingsExtension(LogsSettings): class LogsSettingsExtension(LogsSettings):
trace_sip = Setting(type=bool, default=False) trace_sip = Setting(type=bool, default=False)
trace_pjsip = Setting(type=bool, default=False) trace_pjsip = Setting(type=bool, default=False)
trace_messaging = Setting(type=bool, default=False)
trace_msrp = Setting(type=bool, default=False) trace_msrp = Setting(type=bool, default=False)
trace_xcap = Setting(type=bool, default=False) trace_xcap = Setting(type=bool, default=False)
trace_notifications = Setting(type=bool, default=False) trace_notifications = Setting(type=bool, default=False)
......
...@@ -7,7 +7,7 @@ from datetime import datetime ...@@ -7,7 +7,7 @@ from datetime import datetime
from pprint import pformat from pprint import pformat
from application import log from application import log
from application.notification import IObserver, NotificationCenter, ObserverWeakrefProxy from application.notification import IObserver, NotificationCenter, NotificationData, ObserverWeakrefProxy
from application.python.queue import EventQueue from application.python.queue import EventQueue
from application.python import Null from application.python import Null
from application.python.types import Singleton from application.python.types import Singleton
...@@ -19,7 +19,7 @@ from sipsimple.configuration.settings import SIPSimpleSettings ...@@ -19,7 +19,7 @@ from sipsimple.configuration.settings import SIPSimpleSettings
from blink.resources import ApplicationData from blink.resources import ApplicationData
__all__ = ['LogManager'] __all__ = ['LogManager', 'MessagingTrace']
@implementer(IObserver) @implementer(IObserver)
...@@ -78,6 +78,7 @@ class LogManager(object, metaclass=Singleton): ...@@ -78,6 +78,7 @@ class LogManager(object, metaclass=Singleton):
self.pid = os.getpid() self.pid = os.getpid()
self.msrp_level = log.level.INFO self.msrp_level = log.level.INFO
self.siptrace_file = Null self.siptrace_file = Null
self.massagestrace_file = Null
self.msrptrace_file = Null self.msrptrace_file = Null
self.pjsiptrace_file = Null self.pjsiptrace_file = Null
self.notifications_file = Null self.notifications_file = Null
...@@ -93,6 +94,8 @@ class LogManager(object, metaclass=Singleton): ...@@ -93,6 +94,8 @@ class LogManager(object, metaclass=Singleton):
notification_center.add_observer(self) notification_center.add_observer(self)
if settings.logs.trace_sip: if settings.logs.trace_sip:
self.siptrace_file = LogFile(os.path.join(ApplicationData.directory, 'logs', 'sip_trace.txt')) self.siptrace_file = LogFile(os.path.join(ApplicationData.directory, 'logs', 'sip_trace.txt'))
if settings.logs.trace_messaging:
self.messagingtrace_file = LogFile(os.path.join(ApplicationData.directory, 'logs', 'messaging_trace.txt'))
if settings.logs.trace_msrp: if settings.logs.trace_msrp:
self.msrptrace_file = LogFile(os.path.join(ApplicationData.directory, 'logs', 'msrp_trace.txt')) self.msrptrace_file = LogFile(os.path.join(ApplicationData.directory, 'logs', 'msrp_trace.txt'))
if settings.logs.trace_pjsip: if settings.logs.trace_pjsip:
...@@ -119,6 +122,7 @@ class LogManager(object, metaclass=Singleton): ...@@ -119,6 +122,7 @@ class LogManager(object, metaclass=Singleton):
self.event_queue = Null self.event_queue = Null
self.siptrace_file = Null self.siptrace_file = Null
self.massagestrace_file = Null
self.msrptrace_file = Null self.msrptrace_file = Null
self.pjsiptrace_file = Null self.pjsiptrace_file = Null
self.notifications_file = Null self.notifications_file = Null
...@@ -135,7 +139,7 @@ class LogManager(object, metaclass=Singleton): ...@@ -135,7 +139,7 @@ class LogManager(object, metaclass=Singleton):
handler(notification) handler(notification)
settings = SIPSimpleSettings() settings = SIPSimpleSettings()
if notification.name not in ('SIPEngineLog', 'SIPEngineSIPTrace') and settings.logs.trace_notifications: if notification.name not in ('SIPEngineLog', 'SIPEngineSIPTrace', 'MessagingLog') and settings.logs.trace_notifications:
message = 'Notification name=%s sender=%s data=%s' % (notification.name, notification.sender, pformat(notification.data)) message = 'Notification name=%s sender=%s data=%s' % (notification.name, notification.sender, pformat(notification.data))
try: try:
self.notifications_file.write('%s [%s %d]: %s\n' % (datetime.now(), self.name, self.pid, message)) self.notifications_file.write('%s [%s %d]: %s\n' % (datetime.now(), self.name, self.pid, message))
...@@ -148,6 +152,8 @@ class LogManager(object, metaclass=Singleton): ...@@ -148,6 +152,8 @@ class LogManager(object, metaclass=Singleton):
if notification.sender is settings: if notification.sender is settings:
if 'logs.trace_sip' in notification.data.modified: if 'logs.trace_sip' in notification.data.modified:
self.siptrace_file = LogFile(os.path.join(ApplicationData.directory, 'logs', 'sip_trace.txt')) if settings.logs.trace_sip else Null self.siptrace_file = LogFile(os.path.join(ApplicationData.directory, 'logs', 'sip_trace.txt')) if settings.logs.trace_sip else Null
if 'logs.trace_messaging' in notification.data.modified:
self.messagingtrace_file = LogFile(os.path.join(ApplicationData.directory, 'logs', 'messaging_trace.txt')) if settings.logs.trace_messaging else Null
if 'logs.trace_msrp' in notification.data.modified: if 'logs.trace_msrp' in notification.data.modified:
self.msrptrace_file = LogFile(os.path.join(ApplicationData.directory, 'logs', 'msrp_trace.txt')) if settings.logs.trace_msrp else Null self.msrptrace_file = LogFile(os.path.join(ApplicationData.directory, 'logs', 'msrp_trace.txt')) if settings.logs.trace_msrp else Null
if 'logs.trace_pjsip' in notification.data.modified: if 'logs.trace_pjsip' in notification.data.modified:
...@@ -215,6 +221,17 @@ class LogManager(object, metaclass=Singleton): ...@@ -215,6 +221,17 @@ class LogManager(object, metaclass=Singleton):
except Exception: except Exception:
pass pass
def _LH_MessagingTrace(self, notification):
settings = SIPSimpleSettings()
if not settings.logs.trace_messaging:
return
message = "(%(level)s) %(message)s" % notification.data.__dict__
try:
self.messagingtrace_file.write('%s [%s %d] %s\n' % (notification.datetime, self.name, self.pid, message))
self.messagingtrace_file.flush()
except Exception:
pass
def _LH_MSRPTransportTrace(self, notification): def _LH_MSRPTransportTrace(self, notification):
settings = SIPSimpleSettings() settings = SIPSimpleSettings()
if not settings.logs.trace_msrp: if not settings.logs.trace_msrp:
...@@ -412,3 +429,42 @@ class LogManager(object, metaclass=Singleton): ...@@ -412,3 +429,42 @@ class LogManager(object, metaclass=Singleton):
message = ("%s XCAP manager client did not initialize: %s" % (notification.datetime, notification.data.error)) message = ("%s XCAP manager client did not initialize: %s" % (notification.datetime, notification.data.error))
self.log_xcap(notification, message) self.log_xcap(notification, message)
class MessagingTrace(object, metaclass=Singleton):
@classmethod
def debug(cls, message, *args, **kw):
cls._log('DEBUG', message, *args, **kw)
@classmethod
def info(cls, message, *args, **kw):
cls._log('INFO', message, *args, **kw)
@classmethod
def warning(cls, message, *args, **kw):
cls._log('WARNING', message, *args, **kw)
warn = warning
@classmethod
def error(cls, message, *args, **kw):
cls._log('ERROR', message, *args, **kw)
@classmethod
def exception(cls, message='', *args, **kw):
cls._log('EXCEPTION', message, *args, **kw)
@classmethod
def critical(cls, message, *args, **kw):
cls._log('CRITICAL', message, *args, **kw)
fatal = critical
@classmethod
def _log(cls, level, message):
try:
level = getattr(log.level, level)
except AttributeError:
return
data = NotificationData(level=level, message=message)
notification_center = NotificationCenter()
notification_center.post_notification('MessagingTrace', data=data)
...@@ -317,6 +317,7 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton): ...@@ -317,6 +317,7 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
# File logging # File logging
self.trace_sip_button.clicked.connect(self._SH_TraceSIPButtonClicked) self.trace_sip_button.clicked.connect(self._SH_TraceSIPButtonClicked)
self.trace_messaging_button.clicked.connect(self._SH_TraceMessagingButtonClicked)
self.trace_msrp_button.clicked.connect(self._SH_TraceMSRPButtonClicked) self.trace_msrp_button.clicked.connect(self._SH_TraceMSRPButtonClicked)
self.trace_xcap_button.clicked.connect(self._SH_TraceXCAPButtonClicked) self.trace_xcap_button.clicked.connect(self._SH_TraceXCAPButtonClicked)
self.trace_notifications_button.clicked.connect(self._SH_TraceNotificationsButtonClicked) self.trace_notifications_button.clicked.connect(self._SH_TraceNotificationsButtonClicked)
...@@ -736,6 +737,7 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton): ...@@ -736,6 +737,7 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
# File logging settings # File logging settings
self.trace_sip_button.setChecked(settings.logs.trace_sip) self.trace_sip_button.setChecked(settings.logs.trace_sip)
self.trace_messaging_button.setChecked(settings.logs.trace_messaging)
self.trace_msrp_button.setChecked(settings.logs.trace_msrp) self.trace_msrp_button.setChecked(settings.logs.trace_msrp)
self.trace_xcap_button.setChecked(settings.logs.trace_xcap) self.trace_xcap_button.setChecked(settings.logs.trace_xcap)
self.trace_notifications_button.setChecked(settings.logs.trace_notifications) self.trace_notifications_button.setChecked(settings.logs.trace_notifications)
...@@ -1695,6 +1697,11 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton): ...@@ -1695,6 +1697,11 @@ class PreferencesWindow(base_class, ui_class, metaclass=QSingleton):
settings.logs.trace_sip = checked settings.logs.trace_sip = checked
settings.save() settings.save()
def _SH_TraceMessagingButtonClicked(self, checked):
settings = SIPSimpleSettings()
settings.logs.trace_messaging = checked
settings.save()
def _SH_TraceMSRPButtonClicked(self, checked): def _SH_TraceMSRPButtonClicked(self, checked):
settings = SIPSimpleSettings() settings = SIPSimpleSettings()
settings.logs.trace_msrp = checked settings.logs.trace_msrp = checked
......
...@@ -2980,68 +2980,42 @@ ...@@ -2980,68 +2980,42 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0" colspan="5"> <item row="1" column="0">
<widget class="QCheckBox" name="trace_messaging_button">
<property name="text">
<string>Trace SIP Messaging and PGP Encryption</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="5">
<widget class="QCheckBox" name="trace_msrp_button"> <widget class="QCheckBox" name="trace_msrp_button">
<property name="text"> <property name="text">
<string>Trace MSRP (used for chat, file transfer and screen sharing)</string> <string>Trace MSRP (used for chat, file transfer and screen sharing)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="2" column="0" colspan="5"> <item row="3" column="0" colspan="5">
<widget class="QCheckBox" name="trace_xcap_button"> <widget class="QCheckBox" name="trace_xcap_button">
<property name="text"> <property name="text">
<string>Trace XCAP (used by presence and for storing contacts)</string> <string>Trace XCAP (used by presence and for storing contacts)</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="0" colspan="5"> <item row="4" column="0">
<widget class="QCheckBox" name="trace_notifications_button"> <widget class="QCheckBox" name="trace_notifications_button">
<property name="text"> <property name="text">
<string>Trace Notifications</string> <string>Trace Notifications</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="9" column="0" colspan="5"> <item row="5" column="0">
<spacer name="file_logging_spacer_2"> <widget class="QCheckBox" name="trace_pjsip_button">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="4">
<spacer name="trace_library_spacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="3">
<widget class="QSpinBox" name="pjsip_trace_level">
<property name="maximum">
<number>5</number>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLabel" name="level_label">
<property name="text"> <property name="text">
<string>Level:</string> <string>Trace Core Library</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="1"> <item row="5" column="1">
<spacer name="trace_library_spacer_1"> <spacer name="trace_library_spacer_1">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
...@@ -3057,28 +3031,34 @@ ...@@ -3057,28 +3031,34 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="4" column="0"> <item row="5" column="2">
<widget class="QCheckBox" name="trace_pjsip_button"> <widget class="QLabel" name="level_label">
<property name="text"> <property name="text">
<string>Trace Core Library</string> <string>Level:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="0"> <item row="5" column="3">
<widget class="QPushButton" name="clear_log_files_button"> <widget class="QSpinBox" name="pjsip_trace_level">
<property name="text"> <property name="maximum">
<string>Clear log files</string> <number>5</number>
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="2" colspan="3"> <item row="5" column="4">
<widget class="QLabel" name="log_files_size_label"> <spacer name="trace_library_spacer_2">
<property name="text"> <property name="orientation">
<string>There are currently 0Mb of log files</string> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> <property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item> </item>
<item row="5" column="0" colspan="5"> <item row="6" column="0">
<spacer name="file_logging_spacer_1"> <spacer name="file_logging_spacer_1">
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
...@@ -3094,7 +3074,14 @@ ...@@ -3094,7 +3074,14 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="6" column="1"> <item row="7" column="0">
<widget class="QPushButton" name="clear_log_files_button">
<property name="text">
<string>Clear log files</string>
</property>
</widget>
</item>
<item row="7" column="1">
<spacer name="clear_log_files_spacer"> <spacer name="clear_log_files_spacer">
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
...@@ -3110,6 +3097,26 @@ ...@@ -3110,6 +3097,26 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="7" column="2" colspan="3">
<widget class="QLabel" name="log_files_size_label">
<property name="text">
<string>There are currently 0Mb of log files</string>
</property>
</widget>
</item>
<item row="8" column="0">
<spacer name="file_logging_spacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
...@@ -3961,10 +3968,7 @@ ...@@ -3961,10 +3968,7 @@
<tabstop>trace_sip_button</tabstop> <tabstop>trace_sip_button</tabstop>
<tabstop>trace_msrp_button</tabstop> <tabstop>trace_msrp_button</tabstop>
<tabstop>trace_xcap_button</tabstop> <tabstop>trace_xcap_button</tabstop>
<tabstop>trace_notifications_button</tabstop>
<tabstop>trace_pjsip_button</tabstop>
<tabstop>pjsip_trace_level</tabstop> <tabstop>pjsip_trace_level</tabstop>
<tabstop>clear_log_files_button</tabstop>
<tabstop>enable_udp_button</tabstop> <tabstop>enable_udp_button</tabstop>
<tabstop>enable_tcp_button</tabstop> <tabstop>enable_tcp_button</tabstop>
<tabstop>enable_tls_button</tabstop> <tabstop>enable_tls_button</tabstop>
......
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