From 164ff365107105f379aa537a28c95c8cc0f04e57 Mon Sep 17 00:00:00 2001 From: max-orlov Date: Tue, 28 Nov 2017 17:20:12 +0200 Subject: [PATCH 1/2] ARIA-416 Providing handlers to logging_handlers only adds handles instead of replacing --- aria/orchestrator/context/common.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/aria/orchestrator/context/common.py b/aria/orchestrator/context/common.py index 90205fd5..cb2b37cd 100644 --- a/aria/orchestrator/context/common.py +++ b/aria/orchestrator/context/common.py @@ -115,14 +115,19 @@ def __repr__(self): @contextmanager def logging_handlers(self, handlers=None): + original_handlers = self.logger.handlers handlers = handlers or [] try: for handler in handlers: self.logger.addHandler(handler) + for handler in original_handlers: + self.logger.removeHandler(handler) yield self.logger finally: for handler in handlers: self.logger.removeHandler(handler) + for handler in original_handlers: + self.logger.addHandler(handler) @property def model(self): From 61c2e5f3504d5cdd226c20d7a2a3787b3e64a8cd Mon Sep 17 00:00:00 2001 From: max-orlov Date: Mon, 4 Dec 2017 11:21:32 +0200 Subject: [PATCH 2/2] review 1 --- aria/orchestrator/context/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aria/orchestrator/context/common.py b/aria/orchestrator/context/common.py index cb2b37cd..62b4c8e7 100644 --- a/aria/orchestrator/context/common.py +++ b/aria/orchestrator/context/common.py @@ -114,7 +114,7 @@ def __repr__(self): .format(name=self.__class__.__name__, self=self)) @contextmanager - def logging_handlers(self, handlers=None): + def logging_handlers(self, handlers): original_handlers = self.logger.handlers handlers = handlers or [] try: @@ -124,7 +124,7 @@ def logging_handlers(self, handlers=None): self.logger.removeHandler(handler) yield self.logger finally: - for handler in handlers: + for handler in self.logger.handlers[:]: self.logger.removeHandler(handler) for handler in original_handlers: self.logger.addHandler(handler)