Make the swift3 logger global

Unless we use multiple log_routes, making the logger global is simpler.

Change-Id: I1fcce3b630371def7169a0e4b5f862f555c61e0f
This commit is contained in:
MORITA Kazutaka
2014-07-28 03:36:23 +09:00
parent 373e4158c7
commit aa6521d5df
5 changed files with 15 additions and 22 deletions

View File

@@ -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):

View File

@@ -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):
"""

View File

@@ -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

View File

@@ -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)

View File

@@ -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()