Skip to content

Commit 640a4c6

Browse files
author
Jonathan Warren
committed
Merge pull request #291 from fiatflux/no_propagate_loggers
Don't propagate loggers; add some logging.
2 parents eed8c66 + 3179ea3 commit 640a4c6

2 files changed

Lines changed: 30 additions & 30 deletions

File tree

src/debug.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,15 @@
4848
'loggers': {
4949
'console_only': {
5050
'handlers': ['console'],
51+
'propagate' : 0
5152
},
5253
'file_only': {
5354
'handlers': ['file'],
55+
'propagate' : 0
5456
},
5557
'both': {
5658
'handlers': ['console', 'file'],
59+
'propagate' : 0
5760
},
5861
},
5962
'root': {

src/shared.py

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import random
2222
import highlevelcrypto
2323
import shared
24+
from debug import logger
2425

2526
config = ConfigParser.SafeConfigParser()
2627
myECCryptorObjects = {}
@@ -118,7 +119,8 @@ def lookupAppdataFolder():
118119
if "HOME" in environ:
119120
dataFolder = path.join(os.environ["HOME"], "Library/Application Support/", APPNAME) + '/'
120121
else:
121-
print 'Could not find home folder, please report this message and your OS X version to the BitMessage Github.'
122+
logger.critical('Could not find home folder, please report this message and your '
123+
'OS X version to the BitMessage Github.')
122124
sys.exit()
123125

124126
elif 'win32' in sys.platform or 'win64' in sys.platform:
@@ -129,13 +131,14 @@ def lookupAppdataFolder():
129131
dataFolder = path.join(environ["XDG_CONFIG_HOME"], APPNAME)
130132
except KeyError:
131133
dataFolder = path.join(environ["HOME"], ".config", APPNAME)
134+
132135
# Migrate existing data to the proper location if this is an existing install
133136
try:
134-
print "Moving data folder to ~/.config/%s" % APPNAME
137+
logger.info("Moving data folder to %s" % (dataFolder))
135138
move(path.join(environ["HOME"], ".%s" % APPNAME), dataFolder)
136-
dataFolder = dataFolder + '/'
137139
except IOError:
138-
dataFolder = dataFolder + '/'
140+
pass
141+
dataFolder = dataFolder + '/'
139142
return dataFolder
140143

141144
def isAddressInMyAddressBook(address):
@@ -200,9 +203,7 @@ def decodeWalletImportFormat(WIFstring):
200203

201204

202205
def reloadMyAddressHashes():
203-
printLock.acquire()
204-
print 'reloading keys from keys.dat file'
205-
printLock.release()
206+
logger.debug('reloading keys from keys.dat file')
206207
myECCryptorObjects.clear()
207208
myAddressesByHash.clear()
208209
#myPrivateKeys.clear()
@@ -221,9 +222,7 @@ def reloadMyAddressHashes():
221222
sys.stderr.write('Error in reloadMyAddressHashes: Can\'t handle address versions other than 2 or 3.\n')
222223

223224
def reloadBroadcastSendersForWhichImWatching():
224-
printLock.acquire()
225-
print 'reloading subscriptions...'
226-
printLock.release()
225+
logger.debug('reloading subscriptions...')
227226
broadcastSendersForWhichImWatching.clear()
228227
MyECSubscriptionCryptorObjects.clear()
229228
sqlLock.acquire()
@@ -246,46 +245,44 @@ def doCleanShutdown():
246245
knownNodesLock.acquire()
247246
UISignalQueue.put(('updateStatusBar','Saving the knownNodes list of peers to disk...'))
248247
output = open(appdata + 'knownnodes.dat', 'wb')
249-
print 'finished opening knownnodes.dat. Now pickle.dump'
248+
logger.info('finished opening knownnodes.dat. Now pickle.dump')
250249
pickle.dump(knownNodes, output)
251-
print 'Completed pickle.dump. Closing output...'
250+
logger.info('Completed pickle.dump. Closing output...')
252251
output.close()
253252
knownNodesLock.release()
254-
printLock.acquire()
255-
print 'Finished closing knownnodes.dat output file.'
256-
printLock.release()
253+
logger.info('Finished closing knownnodes.dat output file.')
257254
UISignalQueue.put(('updateStatusBar','Done saving the knownNodes list of peers to disk.'))
258255

259256
broadcastToSendDataQueues((0, 'shutdown', 'all'))
260257

261-
printLock.acquire()
262-
print 'Flushing inventory in memory out to disk...'
263-
printLock.release()
264-
UISignalQueue.put(('updateStatusBar','Flushing inventory in memory out to disk. This should normally only take a second...'))
258+
logger.info('Flushing inventory in memory out to disk...')
259+
UISignalQueue.put((
260+
'updateStatusBar',
261+
'Flushing inventory in memory out to disk. This should normally only take a second...'))
265262
flushInventory()
266263

267-
#This one last useless query will guarantee that the previous flush committed before we close the program.
264+
# This one last useless query will guarantee that the previous flush committed before we close
265+
# the program.
268266
sqlLock.acquire()
269267
sqlSubmitQueue.put('SELECT address FROM subscriptions')
270268
sqlSubmitQueue.put('')
271269
sqlReturnQueue.get()
272270
sqlSubmitQueue.put('exit')
273271
sqlLock.release()
274-
printLock.acquire()
275-
print 'Finished flushing inventory.'
276-
printLock.release()
277-
278-
time.sleep(.25) #Wait long enough to guarantee that any running proof of work worker threads will check the shutdown variable and exit. If the main thread closes before they do then they won't stop.
272+
logger.info('Finished flushing inventory.')
273+
# Wait long enough to guarantee that any running proof of work worker threads will check the
274+
# shutdown variable and exit. If the main thread closes before they do then they won't stop.
275+
time.sleep(.25)
279276

280277
if safeConfigGetBoolean('bitmessagesettings','daemon'):
281-
printLock.acquire()
282-
print 'Done.'
283-
printLock.release()
278+
logger.info('Clean shutdown complete.')
284279
os._exit(0)
285280

286-
#When you want to command a sendDataThread to do something, like shutdown or send some data, this function puts your data into the queues for each of the sendDataThreads. The sendDataThreads are responsible for putting their queue into (and out of) the sendDataQueues list.
281+
# When you want to command a sendDataThread to do something, like shutdown or send some data, this
282+
# function puts your data into the queues for each of the sendDataThreads. The sendDataThreads are
283+
# responsible for putting their queue into (and out of) the sendDataQueues list.
287284
def broadcastToSendDataQueues(data):
288-
#print 'running broadcastToSendDataQueues'
285+
# logger.debug('running broadcastToSendDataQueues')
289286
for q in sendDataQueues:
290287
q.put((data))
291288

0 commit comments

Comments
 (0)