Skip to content

Commit

Permalink
Logging looks good, besides lack of C++
Browse files Browse the repository at this point in the history
  • Loading branch information
etotheipi committed Jul 12, 2012
1 parent 4798f98 commit c5d6ade
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 21 deletions.
4 changes: 2 additions & 2 deletions ArmoryQt.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,14 +420,14 @@ def chngDev(b):
actCreateNew = self.createAction('&Create &New Wallet', self.createNewWallet)
actImportWlt = self.createAction('&Import Armory Wallet', self.execGetImportWltName)
actRestorePaper = self.createAction('&Restore from Paper Backup', self.execRestorePaperBackup)
actMigrateSatoshi = self.createAction('&Migrate Bitcoin Wallet', self.execMigrateSatoshi)
#actMigrateSatoshi = self.createAction('&Migrate Bitcoin Wallet', self.execMigrateSatoshi)
actAddressBook = self.createAction('View &Address Book', self.execAddressBook)


self.menusList[MENUS.Wallets].addAction(actCreateNew)
self.menusList[MENUS.Wallets].addAction(actImportWlt)
self.menusList[MENUS.Wallets].addAction(actRestorePaper)
self.menusList[MENUS.Wallets].addAction(actMigrateSatoshi)
#self.menusList[MENUS.Wallets].addAction(actMigrateSatoshi)
self.menusList[MENUS.Wallets].addAction(actAddressBook)


Expand Down
88 changes: 75 additions & 13 deletions armoryengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
help="Increase amount of debugging output")
parser.add_option("--nologging", dest="logDisable", action="store_true", default=False,
help="Disable all logging")
parser.add_option("--logcpp", dest="logcpp", action="store_true", default=False,
help="Log C++/SWIG console output by redirecting *all* stdout to log file")

(CLI_OPTIONS, CLI_ARGS) = parser.parse_args()

Expand Down Expand Up @@ -194,7 +196,8 @@ def readVersionInt(verInt):


SETTINGS_PATH = CLI_OPTIONS.settingsPath
ARMORY_LOG_FILE = os.path.join(ARMORY_HOME_DIR, 'armorylog.txt')
ARMORY_LOG_FILE = os.path.join(ARMORY_HOME_DIR, 'armorylog.txt')
#ARMORY_LOG_FILE_CPP = os.path.join(ARMORY_HOME_DIR, 'armorycpplog.txt')



Expand Down Expand Up @@ -271,7 +274,7 @@ class CompressedKeyError(Exception): pass
######### INITIALIZE LOGGING UTILITIES ##########
#
# Setup logging to write INFO+ to file, and WARNING+ to console
# Up to 3 log files will be rotated, 5 MB each.
# In debug mode, will write DEBUG+ to file and INFO+ to console
#
LOGDEBUG = logging.debug
LOGINFO = logging.info
Expand All @@ -293,18 +296,42 @@ class CompressedKeyError(Exception): pass
DEFAULT_FILE_LOGTHRESH -= 10


if CLI_OPTIONS.logDisable:
print 'Logging is disabled'
rootLogger.disabled = True
def chopLogFile(filename, size):
if not os.path.exists(filename):
print 'Log file doesn\'t exist [yet]'
return

logfile = open(filename, 'r')
allLines = logfile.readlines()
logfile.close()

nBytes,nLines = 0,0;
for line in allLines[::-1]:
nBytes += len(line)
nLines += 1
if nBytes>size:
break

logfile = open(filename, 'w')
for line in allLines[-nLines:]:
logfile.write(line)
logfile.close()



# Cut down the log file to just the most recent 100 kB
chopLogFile(ARMORY_LOG_FILE, 100*1024)


# Now set loglevels
DateFormat = '%Y-%m-%d %H:%M:%S'
logging.getLogger('').setLevel(logging.DEBUG)
rotateFormatter = logging.Formatter('%(asctime)s (%(levelname)s) -- %(filename)s::%(lineno)d -- %(message)s', \
datefmt='%Y-%m-%d %H:%M')
rotateHandler = logging.handlers.RotatingFileHandler(ARMORY_LOG_FILE, maxBytes=5*1024*1024, backupCount=3)
rotateHandler.setLevel(DEFAULT_FILE_LOGTHRESH)
rotateHandler.setFormatter(rotateFormatter)
logging.getLogger('').addHandler(rotateHandler)
fileFormatter = logging.Formatter('%(asctime)s (%(levelname)s) -- %(filename)s::%(lineno)d -- %(message)s', \
datefmt=DateFormat)
fileHandler = logging.FileHandler(ARMORY_LOG_FILE)
fileHandler.setLevel(DEFAULT_FILE_LOGTHRESH)
fileHandler.setFormatter(fileFormatter)
logging.getLogger('').addHandler(fileHandler)

consoleFormatter = logging.Formatter('(%(levelname)s) %(message)s')
consoleHandler = logging.StreamHandler()
Expand Down Expand Up @@ -354,6 +381,40 @@ def LOGRAWDATA(rawStr, loglevel=DEFAULT_RAWDATA_LOGLEVEL):

logging.log(loglevel, methodStr + pstr)


cpplogfile = None
if CLI_OPTIONS.logDisable:
print 'Logging is disabled'
rootLogger.disabled = True

# For now, ditch the C++-console-catching. Logging python is enough
# My attempt at C++ logging too was becoming a hack...
"""
elif CLI_OPTIONS.logcpp:
# In order to catch C++ output, we have to redirect ALL stdout
# (which means that console writes by python, too)
cpplogfile = open(ARMORY_LOG_FILE_CPP, 'r')
allLines = cpplogfile.readlines()
cpplogfile.close()
# Chop off the beginning of the file
nBytes,nLines = 0,0;
for line in allLines[::-1]:
nBytes += len(line)
nLines += 1
if nBytes>100*1024:
break
cpplogfile = open(ARMORY_LOG_FILE_CPP, 'w')
print 'nlines:', nLines
for line in allLines[-nLines:]:
print line,
cpplogfile.write(line)
cpplogfile.close()
cpplogfile = open(ARMORY_LOG_FILE_CPP, 'a')
raw_input()
os.dup2(cpplogfile.fileno(), sys.stdout.fileno())
raw_input()
os.dup2(cpplogfile.fileno(), sys.stderr.fileno())
"""


def logexcept_override(type, value, tback):
Expand Down Expand Up @@ -944,7 +1005,7 @@ def verifyChecksum(binaryStr, chksum, hashFunc=hash256, fixIfNecessary=True, \
-- One byte error: return input with fixed byte
-- 2+ bytes error: return ''
This method will check the checksum itself for errors, but not correct them.
This method will check the CHECKSUM ITSELF for errors, but not correct them.
However, for PyBtcWallet serialization, if I determine that it is a chksum
error and simply return the original string, then PyBtcWallet will correct
the checksum in the file, next time it reserializes the data.
Expand Down Expand Up @@ -2083,7 +2144,7 @@ def extendAddressChain(self, secureKdfOutput=None, newIV=None):
next time the user unlocks their wallet. Thus, we have to save off the
data they will need to create the key, to be applied on next unlock.
"""

LOGDEBUG('Extending address chain')
if not self.chaincode.getSize() == 32:
raise KeyDataError, 'No chaincode has been defined to extend chain'

Expand Down Expand Up @@ -2287,6 +2348,7 @@ def chk(a):
#############################################################################
def scanBlockchainForAddress(self):
if TheBDM.isInitialized():
LOGDEBUG('Scanning blockchain for address')
cppWlt = Cpp.BtcWallet()
cppWlt.addAddress_1_(self.getAddr160())
TheBDM.scanBlockchainForTx(cppWlt)
Expand Down
10 changes: 5 additions & 5 deletions qtdialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,11 @@ def verifyInputsBeforeAccept(self):

kdfM, kdfUnit = str(self.edtComputeMem.text()).split(' ')
if kdfUnit.lower()=='mb':
self.kdfBytes = round(float(kdfM))*(1024.0**2)
self.kdfBytes = round(float(kdfM)*(1024.0**2) )
if kdfUnit.lower()=='kb':
self.kdfBytes = round(float(kdfM))*(1024.0)
self.kdfBytes = round(float(kdfM)*(1024.0))

LOGINFO('KDF takes', self.kdfSec, 'sec and', self.kdfBytes, 'bytes')
LOGINFO('KDF takes %0.2fsec and %dbytes', self.kdfSec, self.kdfBytes)
except:
QMessageBox.critical(self, 'Invalid KDF Parameters', \
'Please specify time with units, such as '
Expand Down Expand Up @@ -2316,7 +2316,7 @@ def __init__(self, parent=None, main=None):
layout.addWidget(lblImportDescr, 0,0, 1, 2)
layout.addWidget(self.btnImportFile, 1,0, 1, 2); layout.addWidget(ttip1, 1,2,1,1)
layout.addWidget(self.btnImportPaper, 2,0, 1, 2); layout.addWidget(ttip2, 2,2,1,1)
layout.addWidget(self.btnMigrate, 3,0, 1, 2); layout.addWidget(ttip3, 3,2,1,1)
#layout.addWidget(self.btnMigrate, 3,0, 1, 2); layout.addWidget(ttip3, 3,2,1,1)

if self.main.usermode in (USERMODE.Advanced, USERMODE.Expert):
lbl = QLabel('You can manually add wallets to armory by copying them '
Expand Down Expand Up @@ -5033,7 +5033,7 @@ def validateInputsGetTxDP(self):
self.selectedBehavior = ''
if totalChange>0:
self.change160 = self.determineChangeAddr(utxoSelect)
LOGINFO('Change address behavior: ', self.selectedBehavior)
LOGINFO('Change address behavior: %s', self.selectedBehavior)
if not self.change160:
return
recipValuePairs.append( [self.change160, totalChange])
Expand Down
14 changes: 13 additions & 1 deletion versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ VERSION 0.82.1
the master branch of Armory on github. It will then notify you if
your version is older than the latest one.

- Removed Bitcoin-Qt Wallet Migration
This was causing more confusion than it was helping. Given that
very few users will benefit from it anymore, it has been removed
until the new wallet format is finished.

- Added EULA Acknowledgement
All users will now be presented with a standrad "licence agreement"
dialog when they open Armory the first time. If they do not agree,
Armory will close. This is done due to the lack of exposure of
Linux/OSX users to the EULA that is presented to Windows users
during installation.

#-------------------------------------------------------------------------------
VERSION 0.82

Expand All @@ -34,7 +46,7 @@ VERSION 0.82
New button for each recipient in the send-bitcoins window. Given
the values already entered for other recipients and the transaction
fee, it will compute the max spendable balance for this recipient
and insert it into the "Amount" field. Makes
and insert it into the "Amount" field.

- Specify Change Address (Expert Mode Only!)
The send-bitcoins window now has options in the bottom-left corner
Expand Down

0 comments on commit c5d6ade

Please sign in to comment.