From b2f0cb992cdb8cef7912d1ba401c9a95b3677de9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Sun, 6 Mar 2016 18:04:59 +0100 Subject: [PATCH] Charge HTTP logging to separate child logger of each service Unfortunately log filters only apply to each logger, not to its children, so we have to make sure the http child loggers has the same password filter as the root base filter. --- pyicloud/base.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pyicloud/base.py b/pyicloud/base.py index cc9a4a5..318c020 100644 --- a/pyicloud/base.py +++ b/pyicloud/base.py @@ -57,7 +57,9 @@ class PyiCloudSession(requests.Session): # Charge logging to the right service endpoint callee = inspect.stack()[2] module = inspect.getmodule(callee[0]) - logger = logging.getLogger(module.__name__) + logger = logging.getLogger(module.__name__).getChild('http') + if self.service._password_filter not in logger.filters: + logger.addFilter(self.service._password_filter) logger.debug("%s %s %s", args[0], args[1], kwargs.get('data', '')) @@ -116,7 +118,9 @@ class PyiCloudService(object): self.data = {} self.client_id = str(uuid.uuid1()).upper() self.user = {'apple_id': apple_id, 'password': password} - logger.addFilter(PyiCloudPasswordFilter(password)) + + self._password_filter = PyiCloudPasswordFilter(password) + logger.addFilter(self._password_filter) self._home_endpoint = 'https://www.icloud.com' self._setup_endpoint = 'https://setup.icloud.com/setup/ws/1'