Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace root logger with module loggers #180

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pysyncobj/dns_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import logging
from .monotonic import monotonic as monotonicTime

logger = logging.getLogger(__name__)


class DnsCachingResolver(object):
def __init__(self, cacheTime, failCacheTime):
Expand All @@ -24,7 +26,7 @@ def resolve(self, hostname):
prevIps = ips
ips = self.__doResolve(hostname)
if not ips:
logging.warning("failed to resolve hostname: " + hostname)
logger.warning("failed to resolve hostname: " + hostname)
ips = prevIps
self.__cache[hostname] = (currTime, ips)
return None if not ips else random.choice(ips)
Expand All @@ -49,7 +51,7 @@ def __doResolve(self, hostname):
if not ips:
ips = list(set([addr[4][0] for addr in addrs]))
except socket.gaierror:
logging.warning('failed to resolve host %s', hostname)
logger.warning('failed to resolve host %s', hostname)
ips = []
return ips

Expand Down
12 changes: 7 additions & 5 deletions pysyncobj/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from .atomic_replace import atomicReplace
from .config import SERIALIZER_STATE

logger = logging.getLogger(__name__)


class Serializer(object):
def __init__(self, fileName, transmissionBatchSize, tryUseFork,
Expand Down Expand Up @@ -131,7 +133,7 @@ def getTransmissionData(self, transmissionID):
'transmitted': 0,
}
except:
logging.exception('Failed to open file for transmission')
logger.exception('Failed to open file for transmission')
self.__transmissions.pop(transmissionID, None)
return None
isFirst = transmission['transmitted'] == 0
Expand All @@ -142,7 +144,7 @@ def getTransmissionData(self, transmissionID):
else:
data = transmission['file'].read(self.__transmissionBatchSize)
except:
logging.exception('Error reading transmission file')
logger.exception('Error reading transmission file')
self.__transmissions.pop(transmissionID, None)
return False
size = len(data)
Expand Down Expand Up @@ -178,15 +180,15 @@ def setTransmissionData(self, data):
try:
self.__incomingTransmissionFile = open(tmpFile, 'wb')
except:
logging.exception('Failed to open file for incoming transition')
logger.exception('Failed to open file for incoming transition')
self.__incomingTransmissionFile = None
return False
elif self.__incomingTransmissionFile is None:
return False
try:
self.__incomingTransmissionFile.write(data)
except:
logging.exception('Failed to write incoming transition data')
logger.exception('Failed to write incoming transition data')
self.__incomingTransmissionFile = None
return False
if isLast:
Expand All @@ -195,7 +197,7 @@ def setTransmissionData(self, data):
try:
atomicReplace(tmpFile, self.__fileName)
except:
logging.exception('Failed to rename temporary incoming transition file')
logger.exception('Failed to rename temporary incoming transition file')
return False
return True
return False
Expand Down
14 changes: 8 additions & 6 deletions pysyncobj/syncobj.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def iteritems(v):
from .fast_queue import FastQueue
from .monotonic import monotonic as monotonicTime

logger = logging.getLogger(__name__)


class _RAFT_STATE:
FOLLOWER = 0
Expand Down Expand Up @@ -277,7 +279,7 @@ def __init__(self, selfNode, otherNodes, conf=None, consumers=None, nodeClass =
while not self.__transport.ready:
self.__transport.tryGetReady()
except TransportNotReadyError:
logging.exception('failed to perform initialization')
logger.exception('failed to perform initialization')
raise SyncObjException('BindError') # Backwards compatibility

def destroy(self):
Expand Down Expand Up @@ -505,7 +507,7 @@ def _autoTickThread(self):
try:
self.__transport.tryGetReady()
except TransportNotReadyError:
logging.exception('failed to perform initialization')
logger.exception('failed to perform initialization')
return
finally:
self.__initialised.set()
Expand Down Expand Up @@ -647,7 +649,7 @@ def __applyLogEntries(self):

self.__raftLastApplied += 1
except SyncObjExceptionWrongVer as e:
logging.error(
logger.error(
'request to switch to unsupported code version (self version: %d, requested version: %d)' %
(self.__selfCodeVersion, e.ver))

Expand Down Expand Up @@ -778,7 +780,7 @@ def printStatus(self):
"""Dumps different debug info about cluster to default logger"""
status = self.getStatus()
for k, v in iteritems(status):
logging.info('%s: %s' % (str(k), str(v)))
logger.info('%s: %s' % (str(k), str(v)))

def _printStatus(self):
self.printStatus()
Expand Down Expand Up @@ -1318,7 +1320,7 @@ def __tryLogCompaction(self):
self.__lastSerializedEntry = serializeID

if serializeState == SERIALIZER_STATE.FAILED:
logging.warning('Failed to store full dump')
logger.warning('Failed to store full dump')

if serializeState != SERIALIZER_STATE.NOT_SERIALIZING:
return
Expand Down Expand Up @@ -1390,7 +1392,7 @@ def __loadDumpFile(self, clearJournal):
self.__updateClusterConfiguration([node for node in data[3] if node != self.__selfNode])
self.__onSetCodeVersion(0)
except:
logging.exception('failed to load full dump')
logger.exception('failed to load full dump')

def __updateClusterConfiguration(self, newNodes):
# newNodes: list of Node or node ID
Expand Down