Merge "Only add logging handlers if there currently aren't any"

This commit is contained in:
Jenkins 2013-05-24 06:27:09 +00:00 committed by Gerrit Code Review
commit c07f05ed33
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)