Skip to content

Commit a579e8f

Browse files
committed
Logging fixes.
1 parent 1ff1c1b commit a579e8f

File tree

2 files changed

+31
-29
lines changed

2 files changed

+31
-29
lines changed

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: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ def lookupAppdataFolder():
123123
if "HOME" in environ:
124124
dataFolder = path.join(os.environ["HOME"], "Library/Application Support/", APPNAME) + '/'
125125
else:
126-
print 'Could not find home folder, please report this message and your OS X version to the BitMessage Github.'
126+
logger.critical('Could not find home folder, please report this message and your '
127+
'OS X version to the BitMessage Github.')
127128
sys.exit()
128129

129130
elif 'win32' in sys.platform or 'win64' in sys.platform:
@@ -137,7 +138,7 @@ def lookupAppdataFolder():
137138
# Migrate existing data to the proper location if this is an existing install
138139
if not os.path.exists(dataFolder):
139140
try:
140-
print "Moving data folder to ~/.config/%s" % APPNAME
141+
logger.info("Moving data folder to %s" % (dataFolder))
141142
move(path.join(environ["HOME"], ".%s" % APPNAME), dataFolder)
142143
dataFolder = dataFolder
143144
except IOError:
@@ -195,21 +196,22 @@ def decodeWalletImportFormat(WIFstring):
195196
fullString = arithmetic.changebase(WIFstring,58,256)
196197
privkey = fullString[:-4]
197198
if fullString[-4:] != hashlib.sha256(hashlib.sha256(privkey).digest()).digest()[:4]:
198-
sys.stderr.write('Major problem! When trying to decode one of your private keys, the checksum failed. Here is the PRIVATE key: %s\n' % str(WIFstring))
199+
logger.error('Major problem! When trying to decode one of your private keys, the checksum '
200+
'failed. Here is the PRIVATE key: %s\n' % str(WIFstring))
199201
return ""
200202
else:
201203
#checksum passed
202204
if privkey[0] == '\x80':
203205
return privkey[1:]
204206
else:
205-
sys.stderr.write('Major problem! When trying to decode one of your private keys, the checksum passed but the key doesn\'t begin with hex 80. Here is the PRIVATE key: %s\n' % str(WIFstring))
207+
logger.error('Major problem! When trying to decode one of your private keys, the '
208+
'checksum passed but the key doesn\'t begin with hex 80. Here is the '
209+
'PRIVATE key: %s\n' % str(WIFstring))
206210
return ""
207211

208212

209213
def reloadMyAddressHashes():
210-
printLock.acquire()
211-
print 'reloading keys from keys.dat file'
212-
printLock.release()
214+
logger.debug('reloading keys from keys.dat file')
213215
myECCryptorObjects.clear()
214216
myAddressesByHash.clear()
215217
#myPrivateKeys.clear()
@@ -241,9 +243,7 @@ def reloadMyAddressHashes():
241243
fixSensitiveFilePermissions(appdata + 'keys.dat', hasEnabledKeys)
242244

243245
def reloadBroadcastSendersForWhichImWatching():
244-
printLock.acquire()
245-
print 'reloading subscriptions...'
246-
printLock.release()
246+
logger.debug('reloading subscriptions...')
247247
broadcastSendersForWhichImWatching.clear()
248248
MyECSubscriptionCryptorObjects.clear()
249249
sqlLock.acquire()
@@ -266,46 +266,44 @@ def doCleanShutdown():
266266
knownNodesLock.acquire()
267267
UISignalQueue.put(('updateStatusBar','Saving the knownNodes list of peers to disk...'))
268268
output = open(appdata + 'knownnodes.dat', 'wb')
269-
print 'finished opening knownnodes.dat. Now pickle.dump'
269+
logger.info('finished opening knownnodes.dat. Now pickle.dump')
270270
pickle.dump(knownNodes, output)
271-
print 'Completed pickle.dump. Closing output...'
271+
logger.info('Completed pickle.dump. Closing output...')
272272
output.close()
273273
knownNodesLock.release()
274-
printLock.acquire()
275-
print 'Finished closing knownnodes.dat output file.'
276-
printLock.release()
274+
logger.info('Finished closing knownnodes.dat output file.')
277275
UISignalQueue.put(('updateStatusBar','Done saving the knownNodes list of peers to disk.'))
278276

279277
broadcastToSendDataQueues((0, 'shutdown', 'all'))
280278

281-
printLock.acquire()
282-
print 'Flushing inventory in memory out to disk...'
283-
printLock.release()
284-
UISignalQueue.put(('updateStatusBar','Flushing inventory in memory out to disk. This should normally only take a second...'))
279+
logger.info('Flushing inventory in memory out to disk...')
280+
UISignalQueue.put(('updateStatusBar','Flushing inventory in memory out to disk. '
281+
'This should normally only take a second...'))
285282
flushInventory()
286283

287-
#This one last useless query will guarantee that the previous flush committed before we close the program.
284+
# This one last useless query will guarantee that the previous flush committed before we close
285+
# the program.
288286
sqlLock.acquire()
289287
sqlSubmitQueue.put('SELECT address FROM subscriptions')
290288
sqlSubmitQueue.put('')
291289
sqlReturnQueue.get()
292290
sqlSubmitQueue.put('exit')
293291
sqlLock.release()
294-
printLock.acquire()
295-
print 'Finished flushing inventory.'
296-
printLock.release()
292+
logger.info('Finished flushing inventory.')
297293

298-
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.
294+
# Wait long enough to guarantee that any running proof of work worker threads will check the
295+
# shutdown variable and exit. If the main thread closes before they do then they won't stop.
296+
time.sleep(.25)
299297

300298
if safeConfigGetBoolean('bitmessagesettings','daemon'):
301-
printLock.acquire()
302-
print 'Done.'
303-
printLock.release()
299+
logger.info('Clean shutdown complete.')
304300
os._exit(0)
305301

306-
#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.
302+
# When you want to command a sendDataThread to do something, like shutdown or send some data, this
303+
# function puts your data into the queues for each of the sendDataThreads. The sendDataThreads are
304+
# responsible for putting their queue into (and out of) the sendDataQueues list.
307305
def broadcastToSendDataQueues(data):
308-
#print 'running broadcastToSendDataQueues'
306+
# logger.debug('running broadcastToSendDataQueues')
309307
for q in sendDataQueues:
310308
q.put((data))
311309

@@ -332,6 +330,7 @@ def fixPotentiallyInvalidUTF8Data(text):
332330

333331
# Checks sensitive file permissions for inappropriate umask during keys.dat creation.
334332
# (Or unwise subsequent chmod.)
333+
#
335334
# Returns true iff file appears to have appropriate permissions.
336335
def checkSensitiveFilePermissions(filename):
337336
if sys.platform == 'win32':

0 commit comments

Comments
 (0)