diff --git a/swift3/controllers/base.py b/swift3/controllers/base.py index e5730bdc..5d507be9 100644 --- a/swift3/controllers/base.py +++ b/swift3/controllers/base.py @@ -15,13 +15,8 @@ import functools -from swift.common.utils import get_logger - from swift3.response import S3NotImplemented, InvalidRequest -from swift3.utils import camel_to_snake -from swift3.cfg import CONF - -LOGGER = get_logger(CONF, log_route='swift3') +from swift3.utils import LOGGER, camel_to_snake def bucket_operation(func=None, err_resp=None, err_msg=None): diff --git a/swift3/controllers/bucket.py b/swift3/controllers/bucket.py index 53e736d7..b5ce5044 100644 --- a/swift3/controllers/bucket.py +++ b/swift3/controllers/bucket.py @@ -16,7 +16,6 @@ from simplejson import loads from swift.common.http import HTTP_OK -from swift.common.utils import get_logger from swift3.controllers.base import Controller from swift3.controllers.acl import add_canonical_user, swift_acl_translate @@ -24,11 +23,10 @@ from swift3.etree import Element, SubElement, tostring, fromstring from swift3.response import HTTPOk, S3NotImplemented, InvalidArgument, \ MalformedXML, InvalidLocationConstraint from swift3.cfg import CONF +from swift3.utils import LOGGER MAX_PUT_BUCKET_BODY_SIZE = 10240 -LOGGER = get_logger(CONF, log_route='swift3') - class BucketController(Controller): """ diff --git a/swift3/etree.py b/swift3/etree.py index 715408eb..364bf73b 100644 --- a/swift3/etree.py +++ b/swift3/etree.py @@ -17,16 +17,11 @@ import lxml.etree from copy import deepcopy from pkg_resources import resource_stream -from swift.common.utils import get_logger - from swift3.exception import S3Exception -from swift3.utils import camel_to_snake -from swift3.cfg import CONF +from swift3.utils import LOGGER, camel_to_snake XMLNS_S3 = 'http://s3.amazonaws.com/doc/2006-03-01/' -LOGGER = get_logger(CONF, log_route='swift3') - class DocumentInvalid(S3Exception, lxml.etree.DocumentInvalid): pass diff --git a/swift3/middleware.py b/swift3/middleware.py index 4533db19..5d988085 100644 --- a/swift3/middleware.py +++ b/swift3/middleware.py @@ -54,13 +54,12 @@ following for an SAIO setup:: import re -from swift.common.utils import get_logger - from swift3.exception import NotS3Request from swift3.request import Request from swift3.response import ErrorResponse, InternalError, MethodNotAllowed, \ ResponseBase from swift3.cfg import CONF +from swift3.utils import LOGGER def validate_bucket_name(name): @@ -93,7 +92,6 @@ class Swift3Middleware(object): """Swift3 S3 compatibility midleware""" def __init__(self, app, *args, **kwargs): self.app = app - self.logger = get_logger(CONF, log_route='swift3') def __call__(self, env, start_response): try: @@ -103,10 +101,10 @@ class Swift3Middleware(object): resp = self.app except ErrorResponse as err_resp: if isinstance(err_resp, InternalError): - self.logger.exception(err_resp) + LOGGER.exception(err_resp) resp = err_resp except Exception as e: - self.logger.exception(e) + LOGGER.exception(e) resp = InternalError(reason=e) if isinstance(resp, ResponseBase) and 'swift.trans_id' in env: @@ -116,8 +114,8 @@ class Swift3Middleware(object): return resp(env, start_response) def handle_request(self, req): - self.logger.debug('Calling Swift3 Middleware') - self.logger.debug(req.__dict__) + LOGGER.debug('Calling Swift3 Middleware') + LOGGER.debug(req.__dict__) controller = req.controller(self.app) diff --git a/swift3/utils.py b/swift3/utils.py index c17f94cd..06b8ed33 100644 --- a/swift3/utils.py +++ b/swift3/utils.py @@ -16,6 +16,13 @@ import re +from swift.common.utils import get_logger + +from swift3.cfg import CONF + +LOGGER = get_logger(CONF, log_route='swift3') + + def camel_to_snake(camel): return re.sub('(.)([A-Z])', r'\1_\2', camel).lower()