Portable mode moves debug.log

This commit is contained in:
Jonathan Warren 2013-07-15 15:45:03 -04:00
parent 558dcf8550
commit 08694ecc38
3 changed files with 64 additions and 37 deletions

View File

@ -29,6 +29,8 @@ import os
from pyelliptic.openssl import OpenSSL from pyelliptic.openssl import OpenSSL
import pickle import pickle
import platform import platform
import debug
from debug import logger
try: try:
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
@ -1874,7 +1876,14 @@ class MyForm(QtGui.QMainWindow):
shared.knownNodesLock.release() shared.knownNodesLock.release()
os.remove(shared.appdata + 'keys.dat') os.remove(shared.appdata + 'keys.dat')
os.remove(shared.appdata + 'knownnodes.dat') os.remove(shared.appdata + 'knownnodes.dat')
previousAppdataLocation = shared.appdata
shared.appdata = '' shared.appdata = ''
debug.restartLoggingInUpdatedAppdataLocation()
try:
os.remove(previousAppdataLocation + 'debug.log')
os.remove(previousAppdataLocation + 'debug.log.1')
except:
pass
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... 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...
shared.appdata = shared.lookupAppdataFolder() shared.appdata = shared.lookupAppdataFolder()
@ -1894,6 +1903,12 @@ class MyForm(QtGui.QMainWindow):
shared.knownNodesLock.release() shared.knownNodesLock.release()
os.remove('keys.dat') os.remove('keys.dat')
os.remove('knownnodes.dat') os.remove('knownnodes.dat')
debug.restartLoggingInUpdatedAppdataLocation()
try:
os.remove('debug.log')
os.remove('debug.log.1')
except:
pass
def click_radioButtonBlacklist(self): def click_radioButtonBlacklist(self):
if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'white': if shared.config.get('bitmessagesettings', 'blackwhitelist') == 'white':

View File

@ -5,6 +5,7 @@ import time
import shutil # used for moving the messages.dat file import shutil # used for moving the messages.dat file
import sys import sys
import os import os
from debug import logger
# This thread exists because SQLITE3 is so un-threadsafe that we must # This thread exists because SQLITE3 is so un-threadsafe that we must
# submit queries to it and it puts results back in a different queue. They # submit queries to it and it puts results back in a different queue. They

View File

@ -23,48 +23,59 @@ import shared
# TODO(xj9): Get from a config file. # TODO(xj9): Get from a config file.
log_level = 'DEBUG' log_level = 'DEBUG'
logging.config.dictConfig({ def configureLogging():
'version': 1, logging.config.dictConfig({
'formatters': { 'version': 1,
'default': { 'formatters': {
'format': '%(asctime)s - %(levelname)s - %(message)s', 'default': {
'format': '%(asctime)s - %(levelname)s - %(message)s',
},
}, },
}, 'handlers': {
'handlers': { 'console': {
'console': { 'class': 'logging.StreamHandler',
'class': 'logging.StreamHandler', 'formatter': 'default',
'formatter': 'default', 'level': log_level,
'level': log_level, 'stream': 'ext://sys.stdout'
'stream': 'ext://sys.stdout' },
'file': {
'class': 'logging.handlers.RotatingFileHandler',
'formatter': 'default',
'level': log_level,
'filename': shared.appdata + 'debug.log',
'maxBytes': 2097152, # 2 MiB
'backupCount': 1,
}
}, },
'file': { 'loggers': {
'class': 'logging.handlers.RotatingFileHandler', 'console_only': {
'formatter': 'default', 'handlers': ['console'],
'propagate' : 0
},
'file_only': {
'handlers': ['file'],
'propagate' : 0
},
'both': {
'handlers': ['console', 'file'],
'propagate' : 0
},
},
'root': {
'level': log_level, 'level': log_level,
'filename': shared.appdata + 'debug.log',
'maxBytes': 2097152, # 2 MiB
'backupCount': 1,
}
},
'loggers': {
'console_only': {
'handlers': ['console'], 'handlers': ['console'],
'propagate' : 0
}, },
'file_only': { })
'handlers': ['file'],
'propagate' : 0
},
'both': {
'handlers': ['console', 'file'],
'propagate' : 0
},
},
'root': {
'level': log_level,
'handlers': ['console'],
},
})
# TODO (xj9): Get from a config file. # TODO (xj9): Get from a config file.
#logger = logging.getLogger('console_only') #logger = logging.getLogger('console_only')
configureLogging()
logger = logging.getLogger('both') logger = logging.getLogger('both')
def restartLoggingInUpdatedAppdataLocation():
global logger
for i in list(logger.handlers):
logger.removeHandler(i)
i.flush()
i.close()
configureLogging()
logger = logging.getLogger('both')