From 4d888fb13a6bc5094b53915fd48c947e2c6c1736 Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Sat, 1 Jan 2022 10:49:34 -0800 Subject: [PATCH] common: Stop translating log messages Change-Id: I128a64c6126014774bf6218502e6bfdea63b783f Partial-Bug: #1674543 --- swift/common/db_auditor.py | 4 ++-- swift/common/middleware/catch_errors.py | 4 +--- swift/common/middleware/cname_lookup.py | 8 +++----- swift/common/middleware/crypto/crypto_utils.py | 9 ++++----- swift/common/middleware/crypto/decrypter.py | 9 ++++----- swift/common/middleware/ratelimit.py | 13 ++++++------- swift/common/middleware/recon.py | 13 ++++++------- 7 files changed, 26 insertions(+), 34 deletions(-) diff --git a/swift/common/db_auditor.py b/swift/common/db_auditor.py index ee2c1fb574..5a4d7f7831 100644 --- a/swift/common/db_auditor.py +++ b/swift/common/db_auditor.py @@ -96,7 +96,7 @@ class DatabaseAuditor(Daemon): time.sleep(random() * self.interval) while True: self.logger.info( - 'Begin {} audit pass.'.format(self.server_type)) + 'Begin %s audit pass.', self.server_type) begin = time.time() try: reported = self._one_audit_pass(reported) @@ -116,7 +116,7 @@ class DatabaseAuditor(Daemon): def run_once(self, *args, **kwargs): """Run the database audit once.""" self.logger.info( - 'Begin {} audit "once" mode'.format(self.server_type)) + 'Begin %s audit "once" mode', self.server_type) begin = reported = time.time() self._one_audit_pass(reported) elapsed = time.time() - begin diff --git a/swift/common/middleware/catch_errors.py b/swift/common/middleware/catch_errors.py index 70ccfa6023..f737cfdde7 100644 --- a/swift/common/middleware/catch_errors.py +++ b/swift/common/middleware/catch_errors.py @@ -13,8 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from swift import gettext_ as _ - from swift.common.swob import Request, HTTPServerError from swift.common.utils import get_logger, generate_trans_id, close_if_possible from swift.common.wsgi import WSGIContext @@ -74,7 +72,7 @@ class CatchErrorsContext(WSGIContext): # catch any errors in the pipeline resp = self._app_call(env) except: # noqa - self.logger.exception(_('Error: An error occurred')) + self.logger.exception('Error: An error occurred') resp = HTTPServerError(request=Request(env), body=b'An error occurred', content_type='text/plain') diff --git a/swift/common/middleware/cname_lookup.py b/swift/common/middleware/cname_lookup.py index 2578c08fcf..8cf5123e14 100644 --- a/swift/common/middleware/cname_lookup.py +++ b/swift/common/middleware/cname_lookup.py @@ -29,8 +29,6 @@ rewritten and the request is passed further down the WSGI chain. import six -from swift import gettext_ as _ - try: import dns.resolver import dns.exception @@ -167,7 +165,7 @@ class CNAMELookupMiddleware(object): elif self._domain_endswith_in_storage_domain(found_domain): # Found it! self.logger.info( - _('Mapped %(given_domain)s to %(found_domain)s') % + 'Mapped %(given_domain)s to %(found_domain)s', {'given_domain': given_domain, 'found_domain': found_domain}) if port: @@ -180,8 +178,8 @@ class CNAMELookupMiddleware(object): else: # try one more deep in the chain self.logger.debug( - _('Following CNAME chain for ' - '%(given_domain)s to %(found_domain)s') % + 'Following CNAME chain for ' + '%(given_domain)s to %(found_domain)s', {'given_domain': given_domain, 'found_domain': found_domain}) a_domain = found_domain diff --git a/swift/common/middleware/crypto/crypto_utils.py b/swift/common/middleware/crypto/crypto_utils.py index 43f93ce4e3..16beceddd2 100644 --- a/swift/common/middleware/crypto/crypto_utils.py +++ b/swift/common/middleware/crypto/crypto_utils.py @@ -22,7 +22,6 @@ from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes import six from six.moves.urllib import parse as urlparse -from swift import gettext_ as _ from swift.common.exceptions import EncryptionException, UnknownSecretIdError from swift.common.swob import HTTPInternalServerError from swift.common.utils import get_logger @@ -160,7 +159,7 @@ class CryptoWSGIContext(WSGIContext): try: fetch_crypto_keys = env[CRYPTO_KEY_CALLBACK] except KeyError: - self.logger.exception(_('ERROR get_keys() missing callback')) + self.logger.exception('ERROR get_keys() missing callback') raise HTTPInternalServerError( "Unable to retrieve encryption keys.") @@ -181,12 +180,12 @@ class CryptoWSGIContext(WSGIContext): self.crypto.check_key(key) continue except KeyError: - self.logger.exception(_("Missing key for %r") % name) + self.logger.exception("Missing key for %r", name) except TypeError: - self.logger.exception(_("Did not get a keys dict")) + self.logger.exception("Did not get a keys dict") except ValueError as e: # don't include the key in any messages! - self.logger.exception(_("Bad key for %(name)r: %(err)s") % + self.logger.exception("Bad key for %(name)r: %(err)s", {'name': name, 'err': e}) raise HTTPInternalServerError( "Unable to retrieve encryption keys.") diff --git a/swift/common/middleware/crypto/decrypter.py b/swift/common/middleware/crypto/decrypter.py index 2ca3b2ec7c..3ede9b2ebc 100644 --- a/swift/common/middleware/crypto/decrypter.py +++ b/swift/common/middleware/crypto/decrypter.py @@ -16,7 +16,6 @@ import base64 import json -from swift import gettext_ as _ from swift.common.header_key_dict import HeaderKeyDict from swift.common.http import is_success from swift.common.middleware.crypto.crypto_utils import CryptoWSGIContext, \ @@ -77,10 +76,10 @@ class BaseDecrypterContext(CryptoWSGIContext): crypto_meta['body_key']) except KeyError as err: self.logger.error( - _('Error decrypting %(resp_type)s: Missing %(key)s'), + 'Error decrypting %(resp_type)s: Missing %(key)s', {'resp_type': self.server_type, 'key': err}) except ValueError as err: - self.logger.error(_('Error decrypting %(resp_type)s: %(reason)s'), + self.logger.error('Error decrypting %(resp_type)s: %(reason)s', {'resp_type': self.server_type, 'reason': err}) raise HTTPInternalServerError( body='Error decrypting %s' % self.server_type, @@ -178,7 +177,7 @@ class DecrypterObjContext(BaseDecrypterContext): value, key, required, bytes_to_wsgi) except EncryptionException as err: self.logger.error( - _("Error decrypting header %(header)s: %(error)s"), + "Error decrypting header %(header)s: %(error)s", {'header': header, 'error': err}) raise HTTPInternalServerError( body='Error decrypting header', @@ -313,7 +312,7 @@ class DecrypterObjContext(BaseDecrypterContext): try: crypto_meta = self.get_crypto_meta(header, check) except EncryptionException as err: - self.logger.error(_('Error decrypting object: %s'), err) + self.logger.error('Error decrypting object: %s', err) raise HTTPInternalServerError( body='Error decrypting object', content_type='text/plain') return crypto_meta diff --git a/swift/common/middleware/ratelimit.py b/swift/common/middleware/ratelimit.py index 801cb7a842..76ab1db896 100644 --- a/swift/common/middleware/ratelimit.py +++ b/swift/common/middleware/ratelimit.py @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. import time -from swift import gettext_ as _ import eventlet @@ -261,7 +260,7 @@ class RateLimitMiddleware(object): if account_name in self.ratelimit_blacklist or \ account_global_ratelimit == 'BLACKLIST': - self.logger.error(_('Returning 497 because of blacklisting: %s'), + self.logger.error('Returning 497 because of blacklisting: %s', account_name) eventlet.sleep(self.BLACK_LIST_SLEEP) return Response(status='497 Blacklisted', @@ -276,8 +275,8 @@ class RateLimitMiddleware(object): if self.log_sleep_time_seconds and \ need_to_sleep > self.log_sleep_time_seconds: self.logger.warning( - _("Ratelimit sleep log: %(sleep)s for " - "%(account)s/%(container)s/%(object)s"), + "Ratelimit sleep log: %(sleep)s for " + "%(account)s/%(container)s/%(object)s", {'sleep': need_to_sleep, 'account': account_name, 'container': container_name, 'object': obj_name}) if need_to_sleep > 0: @@ -288,8 +287,8 @@ class RateLimitMiddleware(object): else: path = '/'.join((account_name, container_name)) self.logger.error( - _('Returning 498 for %(meth)s to %(path)s. ' - 'Ratelimit (Max Sleep) %(e)s'), + 'Returning 498 for %(meth)s to %(path)s. ' + 'Ratelimit (Max Sleep) %(e)s', {'meth': req.method, 'path': path, 'e': str(e)}) error_resp = Response(status='498 Rate Limited', body='Slow down', request=req) @@ -309,7 +308,7 @@ class RateLimitMiddleware(object): self.memcache_client = cache_from_env(env) if not self.memcache_client: self.logger.warning( - _('Warning: Cannot ratelimit without a memcached client')) + 'Warning: Cannot ratelimit without a memcached client') return self.app(env, start_response) try: version, account, container, obj = req.split_path(1, 4, True) diff --git a/swift/common/middleware/recon.py b/swift/common/middleware/recon.py index 2b58179878..fe4ff941c1 100644 --- a/swift/common/middleware/recon.py +++ b/swift/common/middleware/recon.py @@ -20,7 +20,6 @@ import time from resource import getpagesize from swift import __version__ as swiftver -from swift import gettext_ as _ from swift.common.constraints import check_mount from swift.common.storage_policy import POLICIES from swift.common.swob import Request, Response @@ -89,11 +88,11 @@ class ReconMiddleware(object): if err.errno == errno.ENOENT and ignore_missing: pass else: - self.logger.exception(_('Error reading recon cache file')) + self.logger.exception('Error reading recon cache file') except ValueError: - self.logger.exception(_('Error parsing recon cache file')) + self.logger.exception('Error parsing recon cache file') except Exception: - self.logger.exception(_('Error retrieving recon data')) + self.logger.exception('Error retrieving recon data') return dict((key, None) for key in cache_keys) def get_version(self): @@ -181,7 +180,7 @@ class ReconMiddleware(object): try: return {self.devices: os.listdir(self.devices)} except Exception: - self.logger.exception(_('Error listing devices')) + self.logger.exception('Error listing devices') return {self.devices: None} def get_updater_info(self, recon_type): @@ -277,7 +276,7 @@ class ReconMiddleware(object): except IOError as err: sums[ringfile] = None if err.errno != errno.ENOENT: - self.logger.exception(_('Error reading ringfile')) + self.logger.exception('Error reading ringfile') return sums def get_swift_conf_md5(self): @@ -287,7 +286,7 @@ class ReconMiddleware(object): hexsum = md5_hash_for_file(SWIFT_CONF_FILE) except IOError as err: if err.errno != errno.ENOENT: - self.logger.exception(_('Error reading swift.conf')) + self.logger.exception('Error reading swift.conf') return {SWIFT_CONF_FILE: hexsum} def get_quarantine_count(self):