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
This commit is contained in:
Nicolas Simonds 2013-05-21 16:23:50 -07:00
parent 2925d5bbda
commit e8e7a0e04f
2 changed files with 10 additions and 1 deletions

View File

@ -91,7 +91,7 @@ class HTTPClient(object):
self.auth_plugin = auth_plugin
self._logger = logging.getLogger(__name__)
if self.http_log_debug:
if self.http_log_debug and not self._logger.handlers:
# Logging level is already set on the root logger
ch = logging.StreamHandler()
self._logger.addHandler(ch)

View File

@ -111,3 +111,12 @@ class ClientTest(utils.TestCase):
self.assertRaises(exceptions.BadRequest, cl.get, "/hi")
test_refused_call()
def test_client_logger(self):
cl1 = client.HTTPClient("username", "password", "project_id",
"auth_test", http_log_debug=True)
self.assertEquals(len(cl1._logger.handlers), 1)
cl2 = client.HTTPClient("username", "password", "project_id",
"auth_test", http_log_debug=True)
self.assertEquals(len(cl2._logger.handlers), 1)