Improving info level log messages

String interpolation should be delayed to be handled by the
logging code, rather than being done at the point of the
logging call.

So we should use-

LOG.info(_LI('some message: variable=%s'), variable)

instead of

LOG.info(_LI('some message: variable=%s') % variable)

Change-Id: I6b3e578f2a0b66f253d49fe44766b6a31196a7c4
link: http://docs.openstack.org/developer/oslo.i18n/guidelines.html
This commit is contained in:
sonu.kumar 2015-11-27 12:22:49 +05:30
parent bb9de39180
commit f20ca36d15
13 changed files with 28 additions and 28 deletions

View File

@ -119,7 +119,7 @@ class AgentPoolBackend(base.Backend):
response = None response = None
LOG.info(_LI("Sending '%(msg)s' for '%(zone)s' to '%(server)s:" LOG.info(_LI("Sending '%(msg)s' for '%(zone)s' to '%(server)s:"
"%(port)d'.") % "%(port)d'."),
{'msg': str(opcode), {'msg': str(opcode),
'zone': zone_name, 'server': dest_ip, 'zone': zone_name, 'server': dest_ip,
'port': dest_port}) 'port': dest_port})

View File

@ -345,7 +345,7 @@ class DynECTBackend(base.Backend):
timings=CONF[CFG_GROUP].timings) timings=CONF[CFG_GROUP].timings)
def create_zone(self, context, zone): def create_zone(self, context, zone):
LOG.info(_LI('Creating zone %(d_id)s / %(d_name)s') % LOG.info(_LI('Creating zone %(d_id)s / %(d_name)s'),
{'d_id': zone['id'], 'd_name': zone['name']}) {'d_id': zone['id'], 'd_name': zone['name']})
url = '/Secondary/%s' % zone['name'].rstrip('.') url = '/Secondary/%s' % zone['name'].rstrip('.')
@ -368,7 +368,7 @@ class DynECTBackend(base.Backend):
if emsg['ERR_CD'] == 'TARGET_EXISTS': if emsg['ERR_CD'] == 'TARGET_EXISTS':
msg = _LI("Zone already exists, updating existing " msg = _LI("Zone already exists, updating existing "
"zone instead %s") "zone instead %s")
LOG.info(msg % zone['name']) LOG.info(msg, zone['name'])
client.put(url, data=data) client.put(url, data=data)
break break
else: else:
@ -378,7 +378,7 @@ class DynECTBackend(base.Backend):
client.logout() client.logout()
def delete_zone(self, context, zone): def delete_zone(self, context, zone):
LOG.info(_LI('Deleting zone %(d_id)s / %(d_name)s') % LOG.info(_LI('Deleting zone %(d_id)s / %(d_name)s'),
{'d_id': zone['id'], 'd_name': zone['name']}) {'d_id': zone['id'], 'd_name': zone['name']})
url = '/Zone/%s' % zone['name'].rstrip('.') url = '/Zone/%s' % zone['name'].rstrip('.')
client = self.get_client() client = self.get_client()

View File

@ -26,7 +26,7 @@ class FakeBackend(base.Backend):
__plugin_name__ = 'fake' __plugin_name__ = 'fake'
def create_zone(self, context, zone): def create_zone(self, context, zone):
LOG.info(_LI('Create Zone %r') % zone) LOG.info(_LI('Create Zone %r'), zone)
def delete_zone(self, context, zone): def delete_zone(self, context, zone):
LOG.info(_LI('Delete Zone %r') % zone) LOG.info(_LI('Delete Zone %r'), zone)

View File

@ -43,7 +43,7 @@ class InfobloxBackend(base.Backend):
"Infoblox only supports mDNS instances on port 53") "Infoblox only supports mDNS instances on port 53")
def create_zone(self, context, zone): def create_zone(self, context, zone):
LOG.info(_LI('Create Zone %r') % zone) LOG.info(_LI('Create Zone %r'), zone)
dns_net_view = self.infoblox.get_dns_view(context.tenant) dns_net_view = self.infoblox.get_dns_view(context.tenant)
self.infoblox.create_zone_auth( self.infoblox.create_zone_auth(
@ -52,7 +52,7 @@ class InfobloxBackend(base.Backend):
) )
def delete_zone(self, context, zone): def delete_zone(self, context, zone):
LOG.info(_LI('Delete Zone %r') % zone) LOG.info(_LI('Delete Zone %r'), zone)
self.infoblox.delete_zone_auth(zone['name'][0:-1]) self.infoblox.delete_zone_auth(zone['name'][0:-1])
def ping(self, context): def ping(self, context):

View File

@ -411,7 +411,7 @@ class CentralAPI(object):
# Pool Manager Integration Methods # Pool Manager Integration Methods
def update_status(self, context, zone_id, status, serial): def update_status(self, context, zone_id, status, serial):
LOG.info(_LI("update_status: Calling central's update_status " LOG.info(_LI("update_status: Calling central's update_status "
"for %(zone_id)s : %(status)s : %(serial)s") % "for %(zone_id)s : %(status)s : %(serial)s"),
{'zone_id': zone_id, 'status': status, 'serial': serial}) {'zone_id': zone_id, 'status': status, 'serial': serial})
self.client.cast(context, 'update_status', zone_id=zone_id, self.client.cast(context, 'update_status', zone_id=zone_id,
status=status, serial=serial) status=status, serial=serial)

View File

@ -1091,7 +1091,7 @@ class Service(service.RPCService, service.Service):
'before deleting this zone') 'before deleting this zone')
if hasattr(context, 'abandon') and context.abandon: if hasattr(context, 'abandon') and context.abandon:
LOG.info(_LW("Abandoning zone '%(zone)s'") % {'zone': zone.name}) LOG.info(_LW("Abandoning zone '%(zone)s'"), {'zone': zone.name})
zone = self.storage.delete_zone(context, zone.id) zone = self.storage.delete_zone(context, zone.id)
else: else:
zone = self._delete_zone_in_storage(context, zone) zone = self._delete_zone_in_storage(context, zone)
@ -1151,7 +1151,7 @@ class Service(service.RPCService, service.Service):
"Serial %(srv_serial)d is not equal to zone's %(serial)d," "Serial %(srv_serial)d is not equal to zone's %(serial)d,"
" performing AXFR") " performing AXFR")
LOG.info( LOG.info(
msg % {"srv_serial": serial, "serial": zone.serial}) msg, {"srv_serial": serial, "serial": zone.serial})
self.mdns_api.perform_zone_xfr(context, zone) self.mdns_api.perform_zone_xfr(context, zone)
def count_zones(self, context, criterion=None): def count_zones(self, context, criterion=None):
@ -1977,7 +1977,7 @@ class Service(service.RPCService, service.Service):
except exceptions.ZoneNotFound: except exceptions.ZoneNotFound:
msg = _LI( msg = _LI(
'Creating zone for %(fip_id)s:%(region)s - ' 'Creating zone for %(fip_id)s:%(region)s - '
'%(fip_addr)s zone %(zonename)s') % \ '%(fip_addr)s zone %(zonename)s'), \
{'fip_id': floatingip_id, 'region': region, {'fip_id': floatingip_id, 'region': region,
'fip_addr': fip['address'], 'zonename': zone_name} 'fip_addr': fip['address'], 'zonename': zone_name}
LOG.info(msg) LOG.info(msg)

View File

@ -124,8 +124,8 @@ class DesignateContext(context.RequestContext):
policy.check('use_sudo', self) policy.check('use_sudo', self)
LOG.info(_LI('Accepted sudo from user %(user)s to tenant %(tenant)s') LOG.info(_LI('Accepted sudo from user %(user)s to tenant %(tenant)s'),
% {'user': self.user, 'tenant': tenant}) {'user': self.user, 'tenant': tenant})
self.original_tenant = self.tenant self.original_tenant = self.tenant
self.tenant = tenant self.tenant = tenant

View File

@ -79,7 +79,7 @@ class AkamaiCommands(base.Commands):
client = impl_akamai.EnhancedDNSClient( client = impl_akamai.EnhancedDNSClient(
target.options.get("username"), target.options.get("password")) target.options.get("username"), target.options.get("password"))
LOG.info(_LI("Doing batches of %i") % batch_size) LOG.info(_LI("Doing batches of %i"), batch_size)
criterion = {"pool_id": pool_id} criterion = {"pool_id": pool_id}
marker = None marker = None
@ -103,6 +103,6 @@ class AkamaiCommands(base.Commands):
z = impl_akamai.build_zone(client, target, zone) z = impl_akamai.build_zone(client, target, zone)
update.append(z) update.append(z)
LOG.info(_LI('Uploading %d Zones') % len(update)) LOG.info(_LI('Uploading %d Zones'), len(update))
client.setZones(update) client.setZones(update)

View File

@ -113,7 +113,7 @@ class TLDCommands(base.Commands):
if not os.path.exists(input_file): if not os.path.exists(input_file):
raise Exception('TLD Input file Not Found') raise Exception('TLD Input file Not Found')
LOG.info(_LI("Importing TLDs from %s") % input_file) LOG.info(_LI("Importing TLDs from %s"), input_file)
error_lines = [] error_lines = []
tlds_added = 0 tlds_added = 0
@ -133,7 +133,7 @@ class TLDCommands(base.Commands):
tlds_added += self._validate_and_create_tld(line, tlds_added += self._validate_and_create_tld(line,
error_lines) error_lines)
LOG.info(_LI("Number of tlds added: %d") % tlds_added) LOG.info(_LI("Number of tlds added: %d"), tlds_added)
errors = len(error_lines) errors = len(error_lines)
if errors > 0: if errors > 0:

View File

@ -145,11 +145,11 @@ class RequestHandler(xfr.XFRMixin):
if soa_serial == zone.serial: if soa_serial == zone.serial:
msg = _LI("Serial %(serial)s is the same for master and us for " msg = _LI("Serial %(serial)s is the same for master and us for "
"%(zone_id)s") "%(zone_id)s")
LOG.info(msg % {"serial": soa_serial, "zone_id": zone.id}) LOG.info(msg, {"serial": soa_serial, "zone_id": zone.id})
else: else:
msg = _LI("Scheduling AXFR for %(zone_id)s from %(master_addr)s") msg = _LI("Scheduling AXFR for %(zone_id)s from %(master_addr)s")
info = {"zone_id": zone.id, "master_addr": master_addr} info = {"zone_id": zone.id, "master_addr": master_addr}
LOG.info(msg % info) LOG.info(msg, info)
self.tg.add_thread(self.zone_sync, context, zone, self.tg.add_thread(self.zone_sync, context, zone,
[master_addr]) [master_addr])

View File

@ -176,7 +176,7 @@ class NotifyEndpoint(base.BaseEndpoint):
while retry < max_retries: while retry < max_retries:
retry = retry + 1 retry = retry + 1
LOG.info(_LI("Sending '%(msg)s' for '%(zone)s' to '%(server)s:" LOG.info(_LI("Sending '%(msg)s' for '%(zone)s' to '%(server)s:"
"%(port)d'.") % "%(port)d'."),
{'msg': 'NOTIFY' if notify else 'SOA', {'msg': 'NOTIFY' if notify else 'SOA',
'zone': zone.name, 'server': host, 'zone': zone.name, 'server': host,
'port': port}) 'port': port})
@ -209,7 +209,7 @@ class NotifyEndpoint(base.BaseEndpoint):
# authoritative answer # authoritative answer
elif response.rcode() in (dns.rcode.NXDOMAIN, dns.rcode.REFUSED, elif response.rcode() in (dns.rcode.NXDOMAIN, dns.rcode.REFUSED,
dns.rcode.SERVFAIL): dns.rcode.SERVFAIL):
LOG.info(_LI("%(zone)s not found on %(server)s:%(port)d") % LOG.info(_LI("%(zone)s not found on %(server)s:%(port)d"),
{'zone': zone.name, 'server': host, {'zone': zone.name, 'server': host,
'port': port}) 'port': port})
break break

View File

@ -72,7 +72,7 @@ class MdnsAPI(object):
def notify_zone_changed(self, context, zone, host, port, timeout, def notify_zone_changed(self, context, zone, host, port, timeout,
retry_interval, max_retries, delay): retry_interval, max_retries, delay):
LOG.info(_LI("notify_zone_changed: Calling mdns for zone '%(zone)s', " LOG.info(_LI("notify_zone_changed: Calling mdns for zone '%(zone)s', "
"serial '%(serial)s' to nameserver '%(host)s:%(port)s'") % "serial '%(serial)s' to nameserver '%(host)s:%(port)s'"),
{'zone': zone.name, 'serial': zone.serial, {'zone': zone.name, 'serial': zone.serial,
'host': host, 'port': port}) 'host': host, 'port': port})
# The notify_zone_changed method is a cast rather than a call since the # The notify_zone_changed method is a cast rather than a call since the
@ -87,7 +87,7 @@ class MdnsAPI(object):
retry_interval, max_retries, delay): retry_interval, max_retries, delay):
LOG.info( LOG.info(
_LI("poll_for_serial_number: Calling mdns for zone '%(zone)s', " _LI("poll_for_serial_number: Calling mdns for zone '%(zone)s', "
"serial '%(serial)s' on nameserver '%(host)s:%(port)s'") % "serial '%(serial)s' on nameserver '%(host)s:%(port)s'"),
{'zone': zone.name, 'serial': zone.serial, {'zone': zone.name, 'serial': zone.serial,
'host': nameserver.host, 'port': nameserver.port}) 'host': nameserver.host, 'port': nameserver.port})
# The poll_for_serial_number method is a cast rather than a call since # The poll_for_serial_number method is a cast rather than a call since
@ -103,7 +103,7 @@ class MdnsAPI(object):
retry_interval, max_retries, delay): retry_interval, max_retries, delay):
LOG.info( LOG.info(
_LI("get_serial_number: Calling mdns for zone '%(zone)s', serial " _LI("get_serial_number: Calling mdns for zone '%(zone)s', serial "
"%(serial)s' on nameserver '%(host)s:%(port)s'") % "%(serial)s' on nameserver '%(host)s:%(port)s'"),
{'zone': zone.name, 'serial': zone.serial, {'zone': zone.name, 'serial': zone.serial,
'host': host, 'port': port}) 'host': host, 'port': port})
cctxt = self.notify_client.prepare() cctxt = self.notify_client.prepare()
@ -114,6 +114,6 @@ class MdnsAPI(object):
delay=delay) delay=delay)
def perform_zone_xfr(self, context, zone): def perform_zone_xfr(self, context, zone):
LOG.info(_LI("perform_zone_xfr: Calling mdns for zone %(zone)s") % LOG.info(_LI("perform_zone_xfr: Calling mdns for zone %(zone)s"),
{"zone": zone.name}) {"zone": zone.name})
return self.xfr_client.cast(context, 'perform_zone_xfr', zone=zone) return self.xfr_client.cast(context, 'perform_zone_xfr', zone=zone)

View File

@ -453,7 +453,7 @@ def get_paging_params(params, sort_keys):
def bind_tcp(host, port, tcp_backlog, tcp_keepidle=None): def bind_tcp(host, port, tcp_backlog, tcp_keepidle=None):
# Bind to the TCP port # Bind to the TCP port
LOG.info(_LI('Opening TCP Listening Socket on %(host)s:%(port)d') % LOG.info(_LI('Opening TCP Listening Socket on %(host)s:%(port)d'),
{'host': host, 'port': port}) {'host': host, 'port': port})
sock_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock_tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock_tcp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
@ -480,7 +480,7 @@ def bind_tcp(host, port, tcp_backlog, tcp_keepidle=None):
def bind_udp(host, port): def bind_udp(host, port):
# Bind to the UDP port # Bind to the UDP port
LOG.info(_LI('Opening UDP Listening Socket on %(host)s:%(port)d') % LOG.info(_LI('Opening UDP Listening Socket on %(host)s:%(port)d'),
{'host': host, 'port': port}) {'host': host, 'port': port})
sock_udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock_udp = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock_udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock_udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)