Philipp Hörist pushed to branch master at gajim / gajim
Commits:
-
6e672c99
by Philipp Hörist at 2019-03-08T19:31:05Z
2 changed files:
Changes:
| ... | ... | @@ -24,6 +24,7 @@ import nbxmpp |
| 24 | 24 |
from nbxmpp.structs import StanzaHandler
|
| 25 | 25 |
|
| 26 | 26 |
from gajim.common import app
|
| 27 |
+from gajim.common.modules.util import LogAdapter
|
|
| 27 | 28 |
|
| 28 | 29 |
log = logging.getLogger('gajim.c.m.base')
|
| 29 | 30 |
|
| ... | ... | @@ -33,9 +34,11 @@ class BaseModule: |
| 33 | 34 |
_nbxmpp_extends = ''
|
| 34 | 35 |
_nbxmpp_methods = [] # type: List[str]
|
| 35 | 36 |
|
| 36 |
- def __init__(self, con):
|
|
| 37 |
+ def __init__(self, con, logger=None):
|
|
| 37 | 38 |
self._con = con
|
| 38 | 39 |
self._account = con.name
|
| 40 |
+ if logger is not None:
|
|
| 41 |
+ self._log = LogAdapter(logger, {'account': self._account})
|
|
| 39 | 42 |
self._nbxmpp_callbacks = {} # type: Dict[str, Any]
|
| 40 | 43 |
self._stored_publish = None # type: Callable
|
| 41 | 44 |
self.handlers = [] # type: List[str]
|
| ... | ... | @@ -16,6 +16,7 @@ |
| 16 | 16 |
|
| 17 | 17 |
from typing import Union
|
| 18 | 18 |
|
| 19 |
+from logging import LoggerAdapter
|
|
| 19 | 20 |
from functools import wraps
|
| 20 | 21 |
from functools import partial
|
| 21 | 22 |
|
| ... | ... | @@ -81,3 +82,8 @@ def get_eme_message(eme_data): |
| 81 | 82 |
return EME_MESSAGES[eme_data.namespace]
|
| 82 | 83 |
except KeyError:
|
| 83 | 84 |
return EME_MESSAGES['fallback'] % eme_data.name
|
| 85 |
+ |
|
| 86 |
+ |
|
| 87 |
+class LogAdapter(LoggerAdapter):
|
|
| 88 |
+ def process(self, msg, kwargs):
|
|
| 89 |
+ return '[%s] %s' % (self.extra['account'], msg), kwargs
|