From 74fa2407e371cd11dc57924c176f13f131abefd1 Mon Sep 17 00:00:00 2001 From: Bertrand Lallau Date: Thu, 12 Nov 2015 11:06:55 +0100 Subject: [PATCH] Improve logging in designate.network_api We should delegate (when possible) formatting to the logger in order to perform formatting only when needed, by using: LOG.(message, data) instead of: LOG.(message % data) Change-Id: Ie6e9e18ea13affbb9321fb899d88a2290c56c71f --- designate/network_api/__init__.py | 2 +- designate/network_api/base.py | 2 +- designate/network_api/fake.py | 8 ++++---- designate/network_api/neutron.py | 10 +++++----- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/designate/network_api/__init__.py b/designate/network_api/__init__.py index 7cb105926..1602cf0f3 100644 --- a/designate/network_api/__init__.py +++ b/designate/network_api/__init__.py @@ -28,7 +28,7 @@ cfg.CONF.register_opts([ def get_network_api(network_api_driver): - LOG.debug("Loading network_api driver: %s" % network_api_driver) + LOG.debug("Loading network_api driver: %s", network_api_driver) cls = NetworkAPI.get_driver(network_api_driver) diff --git a/designate/network_api/base.py b/designate/network_api/base.py index 6279e66d0..2b7a0792d 100644 --- a/designate/network_api/base.py +++ b/designate/network_api/base.py @@ -57,7 +57,7 @@ class NetworkAPI(DriverPlugin): msg = 'No service_catalog and no configured endpoints' raise exceptions.ConfigurationError(msg) - LOG.debug('Returning endpoints: %s' % endpoints) + LOG.debug('Returning endpoints: %s', endpoints) return endpoints def _endpoints_from_catalog(self, service_catalog, service_type, diff --git a/designate/network_api/fake.py b/designate/network_api/fake.py index b57f8e014..f7c9553e7 100644 --- a/designate/network_api/fake.py +++ b/designate/network_api/fake.py @@ -46,7 +46,7 @@ def allocate_floatingip(tenant_id, floatingip_id=None): ALLOCATIONS[tenant_id][id_] = POOL.pop(id_) values = _format_floatingip(id_, ALLOCATIONS[tenant_id][id_]) - LOG.debug("Allocated to id_ %s to %s - %s" % (id_, tenant_id, values)) + LOG.debug("Allocated to id_ %s to %s - %s", id_, tenant_id, values) return values @@ -54,7 +54,7 @@ def deallocate_floatingip(id_): """ Deallocate a floatingip """ - LOG.debug('De-allocating %s' % id_) + LOG.debug('De-allocating %s', id_) for tenant_id, allocated in list(ALLOCATIONS.items()): if id_ in allocated: POOL[id_] = allocated.pop(id_) @@ -82,6 +82,6 @@ class FakeNetworkAPI(NetworkAPI): data = list(ALLOCATIONS.get(context.tenant, {}).items()) formatted = [_format_floatingip(k, v) for k, v in data] - LOG.debug('Returning %i FloatingIPs: %s' % - (len(formatted), formatted)) + LOG.debug('Returning %i FloatingIPs: %s', + len(formatted), formatted) return formatted diff --git a/designate/network_api/neutron.py b/designate/network_api/neutron.py index 8c86afad1..b4b5e8275 100644 --- a/designate/network_api/neutron.py +++ b/designate/network_api/neutron.py @@ -110,8 +110,8 @@ class NeutronNetworkAPI(NetworkAPI): def _call(endpoint, region, *args, **kw): client = get_client(context, endpoint=endpoint) - LOG.debug("Attempting to fetch FloatingIPs from %s @ %s" % - (endpoint, region)) + LOG.debug("Attempting to fetch FloatingIPs from %s @ %s", + endpoint, region) try: fips = client.list_floatingips(*args, **kw) except neutron_exceptions.Unauthorized as e: @@ -124,7 +124,7 @@ class NeutronNetworkAPI(NetworkAPI): return except Exception as e: LOG.error(_LE('Failed calling Neutron ' - '%(region)s - %(endpoint)s') % + '%(region)s - %(endpoint)s'), {'region': region, 'endpoint': endpoint}) LOG.exception(e) failed.append((e, endpoint, region)) @@ -137,8 +137,8 @@ class NeutronNetworkAPI(NetworkAPI): 'region': region }) - LOG.debug("Added %i FloatingIPs from %s @ %s" % - (len(data), endpoint, region)) + LOG.debug("Added %i FloatingIPs from %s @ %s", + len(data), endpoint, region) for endpoint, region in endpoints: tg.add_thread(_call, endpoint, region,