Browse Source

lots of log improvements: use debug and utils.logError more

fix-133-memory-crash
Dan Janosik 6 years ago
parent
commit
bb28dda9cf
No known key found for this signature in database GPG Key ID: C6F8CE9FFDB2CED2
  1. 41
      app/utils.js
  2. 14
      routes/baseActionsRouter.js

41
app/utils.js

@ -1,3 +1,8 @@
var debug = require("debug");
var debugLog = debug("btcexp:utils");
var debugErrorLog = debug("btcexp:error");
var Decimal = require("decimal.js"); var Decimal = require("decimal.js");
var request = require("request"); var request = require("request");
var qrcode = require("qrcode"); var qrcode = require("qrcode");
@ -303,7 +308,7 @@ function getTxTotalInputOutputValues(tx, txInputs, blockHeight) {
totalInputValue = totalInputValue.plus(new Decimal(vout.value)); totalInputValue = totalInputValue.plus(new Decimal(vout.value));
} }
} catch (err) { } catch (err) {
console.log("Error getting tx.totalInputValue: err=" + err + ", txid=" + tx.txid + ", index=tx.vin[" + i + "]"); utils.logError("2397gs0gsse", err, {txid:tx.txid, vinIndex:i});
} }
} }
} }
@ -313,7 +318,7 @@ function getTxTotalInputOutputValues(tx, txInputs, blockHeight) {
totalOutputValue = totalOutputValue.plus(new Decimal(tx.vout[i].value)); totalOutputValue = totalOutputValue.plus(new Decimal(tx.vout[i].value));
} }
} catch (err) { } catch (err) {
console.log("Error computing total input/output values for tx: err=" + err + ", tx=" + JSON.stringify(tx) + ", txInputs=" + JSON.stringify(txInputs) + ", blockHeight=" + blockHeight); utils.logError("2308sh0sg44", err, {tx:tx, txInputs:txInputs, blockHeight:blockHeight});
} }
return {input:totalInputValue, output:totalOutputValue}; return {input:totalInputValue, output:totalOutputValue};
@ -368,13 +373,13 @@ function refreshExchangeRates() {
}); });
} }
console.log("Using exchange rates: " + JSON.stringify(global.exchangeRates) + " starting at " + global.exchangeRatesUpdateTime); debugLog("Using exchange rates: " + JSON.stringify(global.exchangeRates) + " starting at " + global.exchangeRatesUpdateTime);
} else { } else {
console.log("Unable to get exchange rate data"); debugLog("Unable to get exchange rate data");
} }
} else { } else {
console.log(`Error 39r7h2390fgewfgds: ${error}, StatusCode: ${(response != null) ? response.statusCode : ""}, Response: ${JSON.stringify(response)}`); utils.logError("39r7h2390fgewfgds", {error:error, response:response, body:body});
} }
}); });
} }
@ -400,7 +405,7 @@ function geoLocateIpAddresses(ipAddresses, provider) {
if (result.value == null) { if (result.value == null) {
var apiUrl = "http://api.ipstack.com/" + result.key + "?access_key=" + config.credentials.ipStackComApiAccessKey; var apiUrl = "http://api.ipstack.com/" + result.key + "?access_key=" + config.credentials.ipStackComApiAccessKey;
console.log("Requesting IP-geo: " + apiUrl); debugLog("Requesting IP-geo: " + apiUrl);
request(apiUrl, function(error, response, body) { request(apiUrl, function(error, response, body) {
if (error) { if (error) {
@ -438,7 +443,7 @@ function geoLocateIpAddresses(ipAddresses, provider) {
resolve(ipDetails); resolve(ipDetails);
}).catch(function(err) { }).catch(function(err) {
console.log("Error 80342hrf78wgehdf07gds: " + err); utils.logError("80342hrf78wgehdf07gds", err);
reject(err); reject(err);
}); });
@ -507,7 +512,27 @@ function colorHexToHsl(hex) {
} }
function logError(errorId, err, optionalUserData = null) { function logError(errorId, err, optionalUserData = null) {
console.log("Error " + errorId + ": " + err + ", json: " + JSON.stringify(err) + (optionalUserData != null ? (", userData: " + optionalUserData) : "")); if (!global.errorLog) {
global.errorLog = [];
}
global.errorLog.push({errorId:errorId, error:err, userData:optionalUserData, date:new Date()});
while (global.errorLog.length > 100) {
global.errorLog.splice(0, 1);
}
debugErrorLog("Error " + errorId + ": " + err + ", json: " + JSON.stringify(err) + (optionalUserData != null ? (", userData: " + optionalUserData + " (json: " + JSON.stringify(optionalUserData) + ")") : ""));
if (err && err.stack) {
debugErrorLog("Stack: " + err.stack);
}
var returnVal = {errorId:errorId, error:err};
if (optionalUserData) {
returnVal.userData = optionalUserData;
}
return returnVal;
} }
function buildQrCodeUrls(strings) { function buildQrCodeUrls(strings) {

14
routes/baseActionsRouter.js

@ -608,13 +608,13 @@ router.get("/address/:address", function(req, res, next) {
res.locals.addressObj = bitcoinjs.address.fromBase58Check(address); res.locals.addressObj = bitcoinjs.address.fromBase58Check(address);
} catch (err) { } catch (err) {
console.log("Error u3gr02gwef: " + err); utils.logError("u3gr02gwef", err);
try { try {
res.locals.addressObj = bitcoinjs.address.fromBech32(address); res.locals.addressObj = bitcoinjs.address.fromBech32(address);
} catch (err2) { } catch (err2) {
console.log("Error u02qg02yqge: " + err2); utils.logError("u02qg02yqge", err);
} }
} }
@ -754,8 +754,8 @@ router.get("/address/:address", function(req, res, next) {
}).catch(function(err) { }).catch(function(err) {
res.locals.electrumHistoryError = err; res.locals.electrumHistoryError = err;
utils.logError("23t07ug2wghefud", err);
console.log("Error 23t07ug2wghefud: " + err + ", error json: " + JSON.stringify(err));
reject(err); reject(err);
}); });
@ -768,7 +768,7 @@ router.get("/address/:address", function(req, res, next) {
resolve(); resolve();
}).catch(function(err) { }).catch(function(err) {
console.log("Error 132r80h32rh: " + err + ", error json: " + JSON.stringify(err)); utils.logError("132r80h32rh", err);
reject(err); reject(err);
}); });
@ -778,7 +778,7 @@ router.get("/address/:address", function(req, res, next) {
promises.push(new Promise(function(resolve, reject) { promises.push(new Promise(function(resolve, reject) {
qrcode.toDataURL(address, function(err, url) { qrcode.toDataURL(address, function(err, url) {
if (err) { if (err) {
console.log("Error 93ygfew0ygf2gf2: " + err); utils.logError("93ygfew0ygf2gf2", err);
} }
res.locals.addressQrCodeUrl = url; res.locals.addressQrCodeUrl = url;
@ -793,7 +793,7 @@ router.get("/address/:address", function(req, res, next) {
next(); next();
}).catch(function(err) { }).catch(function(err) {
console.log("Error 32197rgh327g2: " + err + ", error json: " + JSON.stringify(err)); utils.logError("32197rgh327g2", err);
res.render("address"); res.render("address");
@ -801,6 +801,8 @@ router.get("/address/:address", function(req, res, next) {
}); });
}).catch(function(err) { }).catch(function(err) {
utils.logError("2108hs0gsdfe", err, {address:address});
res.locals.userMessage = "Failed to load address " + address + " (" + err + ")"; res.locals.userMessage = "Failed to load address " + address + " (" + err + ")";
res.render("address"); res.render("address");

Loading…
Cancel
Save