Skip to content

Commit 08694ec

Browse files
author
Jonathan Warren
committed
Portable mode moves debug.log
1 parent 558dcf8 commit 08694ec

File tree

3 files changed

+64
-37
lines changed

3 files changed

+64
-37
lines changed

src/bitmessageqt/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
from pyelliptic.openssl import OpenSSL
3030
import pickle
3131
import platform
32+
import debug
33+
from debug import logger
3234

3335
try:
3436
from PyQt4 import QtCore, QtGui
@@ -1874,7 +1876,14 @@ def click_actionSettings(self):
18741876
shared.knownNodesLock.release()
18751877
os.remove(shared.appdata + 'keys.dat')
18761878
os.remove(shared.appdata + 'knownnodes.dat')
1879+
previousAppdataLocation = shared.appdata
18771880
shared.appdata = ''
1881+
debug.restartLoggingInUpdatedAppdataLocation()
1882+
try:
1883+
os.remove(previousAppdataLocation + 'debug.log')
1884+
os.remove(previousAppdataLocation + 'debug.log.1')
1885+
except:
1886+
pass
18781887

18791888
if shared.appdata == '' and not self.settingsDialogInstance.ui.checkBoxPortableMode.isChecked(): # If we ARE using portable mode now but the user selected that we shouldn't...
18801889
shared.appdata = shared.lookupAppdataFolder()
@@ -1894,6 +1903,12 @@ def click_actionSettings(self):
18941903
shared.knownNodesLock.release()
18951904
os.remove('keys.dat')
18961905
os.remove('knownnodes.dat')
1906+
debug.restartLoggingInUpdatedAppdataLocation()
1907+
try:
1908+
os.remove('debug.log')
1909+
os.remove('debug.log.1')
1910+
except:
1911+
pass
18971912

18981913
def click_radioButtonBlacklist(self):
18991914
if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'white':

src/class_sqlThread.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import shutil # used for moving the messages.dat file
66
import sys
77
import os
8+
from debug import logger
89

910
# This thread exists because SQLITE3 is so un-threadsafe that we must
1011
# submit queries to it and it puts results back in a different queue. They

src/debug.py

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,48 +23,59 @@
2323
# TODO(xj9): Get from a config file.
2424
log_level = 'DEBUG'
2525

26-
logging.config.dictConfig({
27-
'version': 1,
28-
'formatters': {
29-
'default': {
30-
'format': '%(asctime)s - %(levelname)s - %(message)s',
26+
def configureLogging():
27+
logging.config.dictConfig({
28+
'version': 1,
29+
'formatters': {
30+
'default': {
31+
'format': '%(asctime)s - %(levelname)s - %(message)s',
32+
},
3133
},
32-
},
33-
'handlers': {
34-
'console': {
35-
'class': 'logging.StreamHandler',
36-
'formatter': 'default',
37-
'level': log_level,
38-
'stream': 'ext://sys.stdout'
34+
'handlers': {
35+
'console': {
36+
'class': 'logging.StreamHandler',
37+
'formatter': 'default',
38+
'level': log_level,
39+
'stream': 'ext://sys.stdout'
40+
},
41+
'file': {
42+
'class': 'logging.handlers.RotatingFileHandler',
43+
'formatter': 'default',
44+
'level': log_level,
45+
'filename': shared.appdata + 'debug.log',
46+
'maxBytes': 2097152, # 2 MiB
47+
'backupCount': 1,
48+
}
49+
},
50+
'loggers': {
51+
'console_only': {
52+
'handlers': ['console'],
53+
'propagate' : 0
54+
},
55+
'file_only': {
56+
'handlers': ['file'],
57+
'propagate' : 0
58+
},
59+
'both': {
60+
'handlers': ['console', 'file'],
61+
'propagate' : 0
62+
},
3963
},
40-
'file': {
41-
'class': 'logging.handlers.RotatingFileHandler',
42-
'formatter': 'default',
64+
'root': {
4365
'level': log_level,
44-
'filename': shared.appdata + 'debug.log',
45-
'maxBytes': 2097152, # 2 MiB
46-
'backupCount': 1,
47-
}
48-
},
49-
'loggers': {
50-
'console_only': {
5166
'handlers': ['console'],
52-
'propagate' : 0
53-
},
54-
'file_only': {
55-
'handlers': ['file'],
56-
'propagate' : 0
5767
},
58-
'both': {
59-
'handlers': ['console', 'file'],
60-
'propagate' : 0
61-
},
62-
},
63-
'root': {
64-
'level': log_level,
65-
'handlers': ['console'],
66-
},
67-
})
68+
})
6869
# TODO (xj9): Get from a config file.
6970
#logger = logging.getLogger('console_only')
71+
configureLogging()
7072
logger = logging.getLogger('both')
73+
74+
def restartLoggingInUpdatedAppdataLocation():
75+
global logger
76+
for i in list(logger.handlers):
77+
logger.removeHandler(i)
78+
i.flush()
79+
i.close()
80+
configureLogging()
81+
logger = logging.getLogger('both')

0 commit comments

Comments
 (0)