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

View File

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