Skip to content

Commit e8e7a0e

Browse files
committed
Only add logging handlers if there currently aren't any
This corrects an odd problem where Horizon would stand up multiple client objects, which would cause duplicate/triplicate/dozens of repeated log lines in its log files, due to multiple identical handlers being added to the logging object Fixes Bug 1182678 Change-Id: I1f3bae0a39f28412c99e5d04f4364611f2a5facb
1 parent 2925d5b commit e8e7a0e

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

novaclient/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def __init__(self, user, password, projectid, auth_url=None,
9191
self.auth_plugin = auth_plugin
9292

9393
self._logger = logging.getLogger(__name__)
94-
if self.http_log_debug:
94+
if self.http_log_debug and not self._logger.handlers:
9595
# Logging level is already set on the root logger
9696
ch = logging.StreamHandler()
9797
self._logger.addHandler(ch)

tests/test_http.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,12 @@ def test_refused_call():
111111
self.assertRaises(exceptions.BadRequest, cl.get, "/hi")
112112

113113
test_refused_call()
114+
115+
def test_client_logger(self):
116+
cl1 = client.HTTPClient("username", "password", "project_id",
117+
"auth_test", http_log_debug=True)
118+
self.assertEquals(len(cl1._logger.handlers), 1)
119+
120+
cl2 = client.HTTPClient("username", "password", "project_id",
121+
"auth_test", http_log_debug=True)
122+
self.assertEquals(len(cl2._logger.handlers), 1)

0 commit comments

Comments
 (0)