Skip to content

Commit 07b3685

Browse files
authored
Merge pull request #97 from tynanford/master
Switch from twisted logging back to python logging module
2 parents d9a474d + 9d29521 commit 07b3685

File tree

6 files changed

+71
-72
lines changed

6 files changed

+71
-72
lines changed

server/recceiver/announce.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
import struct
55

66
from twisted.internet import protocol
7-
from twisted.logger import Logger
7+
import logging
88

9-
_log = Logger(__name__)
9+
_log = logging.getLogger(__name__)
1010

1111

1212
_Ann = struct.Struct('>HH4sHHI')
@@ -53,14 +53,14 @@ def sendOne(self):
5353
self.D = self.reactor.callLater(self.delay, self.sendOne)
5454
for A in self.udps:
5555
try:
56-
_log.debug('announce to {s}',s=A)
56+
_log.debug('announce to {s}'.format(s=A))
5757
self.transport.write(self.msg, A)
5858
try:
5959
self.udpErr.remove(A)
60-
_log.warn('announce OK to {s}',s=A)
60+
_log.warning('announce OK to {s}'.format(s=A))
6161
except KeyError:
6262
pass
6363
except:
6464
if A not in self.udpErr:
6565
self.udpErr.add(A)
66-
_log.exception('announce Error to {s}',s=A)
66+
_log.exception('announce Error to {s}'.format(s=A))

server/recceiver/application.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
from twisted.internet import defer
1111
from twisted.internet.error import CannotListenError
1212
from twisted.application import service
13-
from twisted.logger import Logger
1413

1514
from .recast import CastFactory
1615
from .udpbcast import SharedUDP
1716
from .announce import Announcer
1817
from .processors import ProcessorController
1918

20-
_log = Logger(__name__)
19+
_log = logging.getLogger(__name__)
2120

2221
class Log2Twisted(logging.StreamHandler):
2322
"""Print logging module stream to the twisted log
@@ -90,7 +89,7 @@ def privilegedStartService(self):
9089

9190
# Find out which port is in use
9291
addr = self.tcp.getHost()
93-
_log.info('RecService listening on {addr}', addr=addr)
92+
_log.info('RecService listening on {addr}'.format(addr=addr))
9493

9594
self.key = random.randint(0,0xffffffff)
9695

@@ -138,7 +137,7 @@ def makeService(self, opts):
138137
lvlname = conf.get('loglevel', 'WARN')
139138
lvl = logging.getLevelName(lvlname)
140139
if not isinstance(lvl, (int, )):
141-
print("Invalid loglevel", lvlname)
140+
print("Invalid loglevel {}. Setting to WARN level instead.".format(lvlname))
142141
lvl = logging.WARN
143142

144143
fmt = conf.get('logformat', "%(levelname)s:%(name)s %(message)s")

server/recceiver/cfstore.py

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# -*- coding: utf-8 -*-
22

3-
from twisted.logger import Logger
3+
import logging
44
import socket
5-
_log = Logger(__name__)
5+
_log = logging.getLogger(__name__)
66

77
from zope.interface import implementer
88

@@ -39,7 +39,7 @@
3939
@implementer(interfaces.IProcessor)
4040
class CFProcessor(service.Service):
4141
def __init__(self, name, conf):
42-
_log.info("CF_INIT {name}", name=name)
42+
_log.info("CF_INIT {name}".format(name=name))
4343
self.name, self.conf = name, conf
4444
self.channel_dict = defaultdict(list)
4545
self.iocs = dict()
@@ -156,7 +156,7 @@ def waitForThread(_ignored):
156156

157157
def chainError(err):
158158
if not err.check(defer.CancelledError):
159-
_log.error("CF_COMMIT FAILURE: {s}", s=err)
159+
_log.error("CF_COMMIT FAILURE: {s}".format(s=err))
160160
if self.cancelled:
161161
if not err.check(defer.CancelledError):
162162
raise defer.CancelledError()
@@ -177,7 +177,7 @@ def _commitWithThread(self, TR):
177177
if not self.running:
178178
raise defer.CancelledError('CF Processor is not running (TR: {host}:{port})', host=TR.src.host, port=TR.src.port)
179179

180-
_log.info("CF_COMMIT: {TR}", TR=TR)
180+
_log.info("CF_COMMIT: {TR}".format(TR=TR))
181181
"""
182182
a dictionary with a list of records with their associated property info
183183
pvInfo
@@ -203,7 +203,7 @@ def _commitWithThread(self, TR):
203203
for rid, (recinfos) in TR.recinfos.items():
204204
# find intersection of these sets
205205
if rid not in pvInfo:
206-
_log.warn('IOC: {iocid}: PV not found for recinfo with RID: {rid}', iocid=iocid, rid=rid)
206+
_log.warning('IOC: {iocid}: PV not found for recinfo with RID: {rid}'.format(iocid=iocid, rid=rid))
207207
continue
208208
recinfo_wl = [p for p in self.whitelist if p in recinfos.keys()]
209209
if recinfo_wl:
@@ -215,7 +215,7 @@ def _commitWithThread(self, TR):
215215

216216
for rid, alias in TR.aliases.items():
217217
if rid not in pvInfo:
218-
_log.warn('IOC: {iocid}: PV not found for alias with RID: {rid}', iocid=iocid, rid=rid)
218+
_log.warning('IOC: {iocid}: PV not found for alias with RID: {rid}'.format(iocid=iocid, rid=rid))
219219
continue
220220
pvInfo[rid]['aliases'] = alias
221221

@@ -228,19 +228,19 @@ def _commitWithThread(self, TR):
228228
pvInfo[rid]['infoProperties'] = list()
229229
pvInfo[rid]['infoProperties'].append(property)
230230
else:
231-
_log.debug('EPICS environment var {env_var} listed in environment_vars setting list not found in this IOC: {iocName}', env_var=epics_env_var_name, iocName=iocName)
231+
_log.debug('EPICS environment var {env_var} listed in environment_vars setting list not found in this IOC: {iocName}'.format(env_var=epics_env_var_name, iocName=iocName))
232232

233233
delrec = list(TR.delrec)
234-
_log.debug("Delete records: {s}", s=delrec)
234+
_log.debug("Delete records: {s}".format(s=delrec))
235235

236236

237237
pvInfoByName = {}
238238
for rid, (info) in pvInfo.items():
239239
if info["pvName"] in pvInfoByName:
240-
_log.warn("Commit contains multiple records with PV name: {pv} ({iocid})", pv=info["pvName"], iocid=iocid)
240+
_log.warning("Commit contains multiple records with PV name: {pv} ({iocid})".format(pv=info["pvName"], iocid=iocid))
241241
continue
242242
pvInfoByName[info["pvName"]] = info
243-
_log.debug("Add record: {rid}: {info}", rid=rid, info=info)
243+
_log.debug("Add record: {rid}: {info}".format(rid=rid, info=info))
244244

245245
if TR.initial:
246246
"""Add IOC to source list """
@@ -301,13 +301,13 @@ def clean_service(self):
301301
_log.info("CF Clean Completed")
302302
return
303303
except RequestException as e:
304-
_log.error("Clean service failed: {s}", s=e)
304+
_log.error("Clean service failed: {s}".format(s=e))
305305
retry_seconds = min(60, sleep)
306-
_log.info("Clean service retry in {retry_seconds} seconds", retry_seconds=retry_seconds)
306+
_log.info("Clean service retry in {retry_seconds} seconds".format(retry_seconds=retry_seconds))
307307
time.sleep(retry_seconds)
308308
sleep *= 1.5
309309
if self.running == 0 and sleep >= retry_limit:
310-
_log.info("Abandoning clean after {retry_limit} seconds", retry_limit=retry_limit)
310+
_log.info("Abandoning clean after {retry_limit} seconds".format(retry_limit=retry_limit))
311311
return
312312

313313
def get_active_channels(self, recceiverid):
@@ -317,8 +317,8 @@ def clean_channels(self, owner, channels):
317317
new_channels = []
318318
for ch in channels or []:
319319
new_channels.append(ch[u'name'])
320-
_log.info("Total channels to update: {nChannels}", nChannels=len(new_channels))
321-
_log.debug('Update "pvStatus" property to "Inactive" for {n_channels} channels', n_channels=len(new_channels))
320+
_log.info("Total channels to update: {nChannels}".format(nChannels=len(new_channels)))
321+
_log.debug('Update "pvStatus" property to "Inactive" for {n_channels} channels'.format(n_channels=len(new_channels)))
322322
self.client.update(property={u'name': 'pvStatus', u'owner': owner, u'value': "Inactive"},
323323
channelNames=new_channels)
324324

@@ -339,7 +339,7 @@ def dict_to_file(dict, iocs, conf):
339339

340340

341341
def __updateCF__(proc, pvInfoByName, delrec, hostName, iocName, iocIP, iocid, owner, iocTime):
342-
_log.info("CF Update IOC: {iocid}", iocid=iocid)
342+
_log.info("CF Update IOC: {iocid}".format(iocid=iocid))
343343

344344
# Consider making this function a class methed then 'proc' simply becomes 'self'
345345
client = proc.client
@@ -356,7 +356,7 @@ def __updateCF__(proc, pvInfoByName, delrec, hostName, iocName, iocIP, iocid, ow
356356
iocTime = iocs[iocid]["time"]
357357
iocIP = iocs[iocid]["iocIP"]
358358
else:
359-
_log.warn('IOC Env Info not found: {iocid}', iocid=iocid)
359+
_log.warning('IOC Env Info not found: {iocid}'.format(iocid=iocid))
360360

361361
if hostName is None or iocName is None:
362362
raise Exception('missing hostName or iocName')
@@ -366,7 +366,7 @@ def __updateCF__(proc, pvInfoByName, delrec, hostName, iocName, iocIP, iocid, ow
366366

367367
channels = []
368368
"""A list of channels in channelfinder with the associated hostName and iocName"""
369-
_log.debug('Find existing channels by IOCID: {iocid}', iocid=iocid)
369+
_log.debug('Find existing channels by IOCID: {iocid}'.format(iocid=iocid))
370370
old = client.findByArgs(prepareFindArgs(conf, [('iocid', iocid)]))
371371
if proc.cancelled:
372372
raise defer.CancelledError()
@@ -381,7 +381,7 @@ def __updateCF__(proc, pvInfoByName, delrec, hostName, iocName, iocIP, iocid, ow
381381
if (conf.get('recordType', 'default') == 'on'):
382382
ch[u'properties'] = __merge_property_lists(ch[u'properties'].append({u'name': 'recordType', u'owner': owner, u'value': iocs[channels_dict[ch[u'name']][-1]]["recordType"]}), ch[u'properties'])
383383
channels.append(ch)
384-
_log.debug("Add existing channel to previous IOC: {s}", s=channels[-1])
384+
_log.debug("Add existing channel to previous IOC: {s}".format(s=channels[-1]))
385385
"""In case alias exist, also delete them"""
386386
if (conf.get('alias', 'default') == 'on'):
387387
if ch[u'name'] in pvInfoByName and "aliases" in pvInfoByName[ch[u'name']]:
@@ -393,15 +393,15 @@ def __updateCF__(proc, pvInfoByName, delrec, hostName, iocName, iocIP, iocid, ow
393393
if (conf.get('recordType', 'default') == 'on'):
394394
ch[u'properties'] = __merge_property_lists(ch[u'properties'].append({u'name': 'recordType', u'owner': owner, u'value': iocs[channels_dict[a[u'name']][-1]]["recordType"]}), ch[u'properties'])
395395
channels.append(a)
396-
_log.debug("Add existing alias to previous IOC: {s}", s=channels[-1])
396+
_log.debug("Add existing alias to previous IOC: {s}".format(s=channels[-1]))
397397

398398
else:
399399
"""Orphan the channel : mark as inactive, keep the old hostName and iocName"""
400400
ch[u'properties'] = __merge_property_lists([{u'name': 'pvStatus', u'owner': owner, u'value': 'Inactive'},
401401
{u'name': 'time', u'owner': owner, u'value': iocTime}],
402402
ch[u'properties'])
403403
channels.append(ch)
404-
_log.debug("Add orphaned channel with no IOC: {s}", s=channels[-1])
404+
_log.debug("Add orphaned channel with no IOC: {s}".format(s=channels[-1]))
405405
"""Also orphan any alias"""
406406
if (conf.get('alias', 'default') == 'on'):
407407
if ch[u'name'] in pvInfoByName and "aliases" in pvInfoByName[ch[u'name']]:
@@ -410,7 +410,7 @@ def __updateCF__(proc, pvInfoByName, delrec, hostName, iocName, iocIP, iocid, ow
410410
{u'name': 'time', u'owner': owner, u'value': iocTime}],
411411
a[u'properties'])
412412
channels.append(a)
413-
_log.debug("Add orphaned alias with no IOC: {s}", s=channels[-1])
413+
_log.debug("Add orphaned alias with no IOC: {s}".format(s=channels[-1]))
414414
else:
415415
if ch[u'name'] in new: # case: channel in old and new
416416
"""
@@ -421,7 +421,7 @@ def __updateCF__(proc, pvInfoByName, delrec, hostName, iocName, iocIP, iocid, ow
421421
{u'name': 'time', u'owner': owner, u'value': iocTime}],
422422
ch[u'properties'])
423423
channels.append(ch)
424-
_log.debug("Add existing channel with same IOC: {s}", s=channels[-1])
424+
_log.debug("Add existing channel with same IOC: {s}".format(s=channels[-1]))
425425
new.remove(ch[u'name'])
426426

427427
"""In case, alias exist"""
@@ -445,7 +445,7 @@ def __updateCF__(proc, pvInfoByName, delrec, hostName, iocName, iocIP, iocid, ow
445445
u'owner': owner,
446446
u'properties': aprops})
447447
new.remove(a[u'name'])
448-
_log.debug("Add existing alias with same IOC: {s}", s=channels[-1])
448+
_log.debug("Add existing alias with same IOC: {s}".format(s=channels[-1]))
449449
# now pvNames contains a list of pv's new on this host/ioc
450450
"""A dictionary representing the current channelfinder information associated with the pvNames"""
451451
existingChannels = {}
@@ -468,7 +468,7 @@ def __updateCF__(proc, pvInfoByName, delrec, hostName, iocName, iocIP, iocid, ow
468468
searchStrings.append(searchString)
469469

470470
for eachSearchString in searchStrings:
471-
_log.debug('Find existing channels by name: {search}', search=eachSearchString)
471+
_log.debug('Find existing channels by name: {search}'.format(search=eachSearchString))
472472
for ch in client.findByArgs(prepareFindArgs(conf, [('~name', eachSearchString)])):
473473
existingChannels[ch["name"]] = ch
474474
if proc.cancelled:
@@ -486,7 +486,7 @@ def __updateCF__(proc, pvInfoByName, delrec, hostName, iocName, iocIP, iocid, ow
486486
existingChannel = existingChannels[pv]
487487
existingChannel["properties"] = __merge_property_lists(newProps, existingChannel["properties"])
488488
channels.append(existingChannel)
489-
_log.debug("Add existing channel with different IOC: {s}", s=channels[-1])
489+
_log.debug("Add existing channel with different IOC: {s}".format(s=channels[-1]))
490490
"""in case, alias exists, update their properties too"""
491491
if (conf.get('alias', 'default') == 'on'):
492492
if pv in pvInfoByName and "aliases" in pvInfoByName[pv]:
@@ -502,14 +502,14 @@ def __updateCF__(proc, pvInfoByName, delrec, hostName, iocName, iocIP, iocid, ow
502502
channels.append({u'name': a,
503503
u'owner': owner,
504504
u'properties': alProps})
505-
_log.debug("Add existing alias with different IOC: {s}", s=channels[-1])
505+
_log.debug("Add existing alias with different IOC: {s}".format(s=channels[-1]))
506506

507507
else:
508508
"""New channel"""
509509
channels.append({u'name': pv,
510510
u'owner': owner,
511511
u'properties': newProps})
512-
_log.debug("Add new channel: {s}", s=channels[-1])
512+
_log.debug("Add new channel: {s}".format(s=channels[-1]))
513513
if (conf.get('alias', 'default') == 'on'):
514514
if pv in pvInfoByName and "aliases" in pvInfoByName[pv]:
515515
alProps = [{u'name': 'alias', u'owner': owner, u'value': pv}]
@@ -519,8 +519,8 @@ def __updateCF__(proc, pvInfoByName, delrec, hostName, iocName, iocIP, iocid, ow
519519
channels.append({u'name': a,
520520
u'owner': owner,
521521
u'properties': alProps})
522-
_log.debug("Add new alias: {s}", s=channels[-1])
523-
_log.info("Total channels to update: {nChannels} {iocName}", nChannels=len(channels), iocName=iocName)
522+
_log.debug("Add new alias: {s}".format(s=channels[-1]))
523+
_log.info("Total channels to update: {nChannels} {iocName}".format(nChannels=len(channels), iocName=iocName))
524524
if len(channels) != 0:
525525
client.set(channels=channels)
526526
else:
@@ -574,7 +574,7 @@ def prepareFindArgs(conf, args, size=0):
574574

575575

576576
def poll(update, proc, pvInfoByName, delrec, hostName, iocName, iocIP, iocid, owner, iocTime):
577-
_log.info("Polling {iocName} begins...", iocName=iocName)
577+
_log.info("Polling {iocName} begins...".format(iocName=iocName))
578578
sleep = 1
579579
success = False
580580
while not success:
@@ -583,10 +583,10 @@ def poll(update, proc, pvInfoByName, delrec, hostName, iocName, iocIP, iocid, ow
583583
success = True
584584
return success
585585
except RequestException as e:
586-
_log.error("ChannelFinder update failed: {s}", s=e)
586+
_log.error("ChannelFinder update failed: {s}".format(s=e))
587587
retry_seconds = min(60, sleep)
588-
_log.info("ChannelFinder update retry in {retry_seconds} seconds", retry_seconds=retry_seconds)
588+
_log.info("ChannelFinder update retry in {retry_seconds} seconds".format(retry_seconds=retry_seconds))
589589
#_log.debug(str(channels_dict))
590590
time.sleep(retry_seconds)
591591
sleep *= 1.5
592-
_log.info("Polling {iocName} complete", iocName=iocName)
592+
_log.info("Polling {iocName} complete".format(iocName=iocName))

server/recceiver/dbstore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
import itertools
4-
from twisted.logger import Logger
4+
import logging
55

66
from zope.interface import implementer
77

@@ -11,7 +11,7 @@
1111

1212
from . import interfaces
1313

14-
_log = Logger(__name__)
14+
_log = logging.getLogger(__name__)
1515

1616
__all__ = ['DBProcessor']
1717

0 commit comments

Comments
 (0)