Add LogAdapter
This adds the account to all log messages issues in module code
This commit is contained in:
parent
b704e27abc
commit
6e672c9911
|
@ -24,6 +24,7 @@ import nbxmpp
|
|||
from nbxmpp.structs import StanzaHandler
|
||||
|
||||
from gajim.common import app
|
||||
from gajim.common.modules.util import LogAdapter
|
||||
|
||||
log = logging.getLogger('gajim.c.m.base')
|
||||
|
||||
|
@ -33,9 +34,11 @@ class BaseModule:
|
|||
_nbxmpp_extends = ''
|
||||
_nbxmpp_methods = [] # type: List[str]
|
||||
|
||||
def __init__(self, con):
|
||||
def __init__(self, con, logger=None):
|
||||
self._con = con
|
||||
self._account = con.name
|
||||
if logger is not None:
|
||||
self._log = LogAdapter(logger, {'account': self._account})
|
||||
self._nbxmpp_callbacks = {} # type: Dict[str, Any]
|
||||
self._stored_publish = None # type: Callable
|
||||
self.handlers = [] # type: List[str]
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
from typing import Union
|
||||
|
||||
from logging import LoggerAdapter
|
||||
from functools import wraps
|
||||
from functools import partial
|
||||
|
||||
|
@ -81,3 +82,8 @@ def get_eme_message(eme_data):
|
|||
return EME_MESSAGES[eme_data.namespace]
|
||||
except KeyError:
|
||||
return EME_MESSAGES['fallback'] % eme_data.name
|
||||
|
||||
|
||||
class LogAdapter(LoggerAdapter):
|
||||
def process(self, msg, kwargs):
|
||||
return '[%s] %s' % (self.extra['account'], msg), kwargs
|
||||
|
|
Loading…
Reference in New Issue