From a8ba7513705fe2a4c9d776c8833ff0f7f6d43ce4 Mon Sep 17 00:00:00 2001 From: Samuel Merritt Date: Wed, 15 Jan 2014 10:31:36 -0800 Subject: [PATCH] Make sure SLO's bulk-delete logger is configured The SLO middleware supports deletion of an object and all its segments; internally, it uses the same code as the bulk middleware to do this (swift.common.middleware.bulk.Bulk). If something goes wrong in the bulk delete, the Bulk object logs the exception; however, SLO's Bulk object's logger always has the default logging config, so if you've got a non-default logging setup (e.g. syslog to a remote log host), this one exception message goes somewhere else (e.g. local syslog). This patch makes SLO and its bulk deleter share a logger so all the messages go to the same place. Change-Id: Idb01b5640257a02dbb9c698851a14ad8fba11a2d --- swift/common/middleware/bulk.py | 4 ++-- swift/common/middleware/slo.py | 2 +- test/unit/common/middleware/test_slo.py | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/swift/common/middleware/bulk.py b/swift/common/middleware/bulk.py index 7cba46cba2..fe9c0bf8fd 100644 --- a/swift/common/middleware/bulk.py +++ b/swift/common/middleware/bulk.py @@ -188,9 +188,9 @@ class Bulk(object): def __init__(self, app, conf, max_containers_per_extraction=10000, max_failed_extractions=1000, max_deletes_per_request=10000, max_failed_deletes=1000, yield_frequency=60, retry_count=0, - retry_interval=1.5): + retry_interval=1.5, logger=None): self.app = app - self.logger = get_logger(conf, log_route='bulk') + self.logger = logger or get_logger(conf, log_route='bulk') self.max_containers = max_containers_per_extraction self.max_failed_extractions = max_failed_extractions self.max_failed_deletes = max_failed_deletes diff --git a/swift/common/middleware/slo.py b/swift/common/middleware/slo.py index f500f598b5..5024b25eb1 100644 --- a/swift/common/middleware/slo.py +++ b/swift/common/middleware/slo.py @@ -594,7 +594,7 @@ class StaticLargeObject(object): 'rate_limit_after_segment', '10')) self.rate_limit_segments_per_sec = int(self.conf.get( 'rate_limit_segments_per_sec', '0')) - self.bulk_deleter = Bulk(app, {}) + self.bulk_deleter = Bulk(app, {}, logger=self.logger) def handle_multipart_get_or_head(self, req, start_response): """ diff --git a/test/unit/common/middleware/test_slo.py b/test/unit/common/middleware/test_slo.py index 01090aa6fe..85995a5838 100644 --- a/test/unit/common/middleware/test_slo.py +++ b/test/unit/common/middleware/test_slo.py @@ -1268,6 +1268,12 @@ class TestSloGetManifest(SloTestCase): ('GET', '/v1/AUTH_test/gettest/c_15')]) +class TestSloBulkLogger(unittest.TestCase): + def test_reused_logger(self): + slo_mware = slo.filter_factory({})('fake app') + self.assertTrue(slo_mware.logger is slo_mware.bulk_deleter.logger) + + class TestSloCopyHook(SloTestCase): def setUp(self): super(TestSloCopyHook, self).setUp()