diff options
author | lovetox <philipp@hoerist.com> | 2020-03-20 17:51:17 +0300 |
---|---|---|
committer | lovetox <philipp@hoerist.com> | 2020-03-20 17:51:17 +0300 |
commit | 5cc8dca3126365ac2dd2296060d516814781f606 (patch) | |
tree | 09a5b05a961452a5b7b4a3c3128ec4f671f75912 /nbxmpp/connection.py | |
parent | 0c7293b8bb01f16a717e736727d7bcad4f888d57 (diff) |
Logging: Add context to logging output
Diffstat (limited to 'nbxmpp/connection.py')
-rw-r--r-- | nbxmpp/connection.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/nbxmpp/connection.py b/nbxmpp/connection.py index 9eefad1..af7ea26 100644 --- a/nbxmpp/connection.py +++ b/nbxmpp/connection.py @@ -21,6 +21,7 @@ from gi.repository import Gio from nbxmpp.const import TCPState from nbxmpp.util import Observable +from nbxmpp.util import LogAdapter log = logging.getLogger('nbxmpp.connection') @@ -39,12 +40,16 @@ class Connection(Observable): disconnected ''' def __init__(self, + log_context, address, accepted_certificates, ignore_tls_errors, ignored_tls_errors, client_cert): - Observable.__init__(self, log) + + self._log = LogAdapter(log, {'context': log_context}) + + Observable.__init__(self, self._log) self._client_cert = client_cert self._address = address @@ -72,23 +77,23 @@ class Connection(Observable): @state.setter def state(self, value): - log.info('Set Connection State: %s', value) + self._log.info('Set Connection State: %s', value) self._state = value def _accept_certificate(self): if not self._peer_certificate_errors: return True - log.info('Found TLS certificate errors: %s', - self._peer_certificate_errors) + self._log.info('Found TLS certificate errors: %s', + self._peer_certificate_errors) if self._ignore_tls_errors: - log.warning('Ignore all errors') + self._log.warning('Ignore all errors') return True if self._ignored_tls_errors: - log.warning('Ignore TLS certificate errors: %s', - self._ignored_tls_errors) + self._log.warning('Ignore TLS certificate errors: %s', + self._ignored_tls_errors) self._peer_certificate_errors -= self._ignored_tls_errors if Gio.TlsCertificateFlags.UNKNOWN_CA in self._peer_certificate_errors: @@ -111,14 +116,13 @@ class Connection(Observable): def send(self, stanza, now=False): raise NotImplementedError - @staticmethod - def _log_stanza(data, received=True): + def _log_stanza(self, data, received=True): direction = 'RECEIVED' if received else 'SENT' message = ('::::: DATA %s ::::' '\n_____________\n' '%s' '\n_____________') - log.info(message, direction, data) + self._log.info(message, direction, data) def start_tls_negotiation(self): raise NotImplementedError |