Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13710993
D13012.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
D13012.diff
View Options
diff --git a/web/alias-server/README.md b/web/alias-server/README.md
--- a/web/alias-server/README.md
+++ b/web/alias-server/README.md
@@ -6,7 +6,7 @@
[x] Template node app
[x] Install chronik and add function for getting tx history
-[] Timestamped logging
+[x] Timestamped logging
[] Match Cashtab alias functions and unit tests
[] Add database
[] Add API endpoint for getting aliases by blockheight
diff --git a/web/alias-server/chronik.js b/web/alias-server/chronik.js
--- a/web/alias-server/chronik.js
+++ b/web/alias-server/chronik.js
@@ -1,4 +1,5 @@
const config = require('./config');
+const log = require('./log');
const { ChronikClient } = require('chronik-client');
const chronik = new ChronikClient(config.chronik);
@@ -12,7 +13,7 @@
.history(page, config.txHistoryPageSize);
return txHistoryPage;
} catch (err) {
- console.log(`Error in getTxHistoryPage(${hash160})`, err);
+ log(`Error in getTxHistoryPage(${hash160})`, err);
}
},
returnGetTxHistoryPagePromise: async function (hash160, page = 0) {
@@ -53,13 +54,6 @@
txHistoryPageResponsePromises.push(txHistoryPageResponsePromise);
}
- // Add a promise that errors to confirm this case is handled
- /*
- const failingPromise =
- module.exports.returnGetTxHistoryPagePromise('not-a-hash160');
- txHistoryPageResponsePromises.push(failingPromise);
- */
-
// Use Promise.all so that an error is thrown if any single promise fails
let remainingTxHistoryPageResponses;
try {
@@ -67,10 +61,7 @@
txHistoryPageResponsePromises,
);
} catch (err) {
- console.log(
- `Error in Promise.all(txHistoryPageResponsePromises)`,
- err,
- );
+ log(`Error in Promise.all(txHistoryPageResponsePromises)`, err);
// Return false; you won't have all the tx history if this happens
return false;
}
diff --git a/web/alias-server/index.js b/web/alias-server/index.js
--- a/web/alias-server/index.js
+++ b/web/alias-server/index.js
@@ -1,11 +1,12 @@
-const { getAllTxHistory } = require('./chronik');
const config = require('./config');
+const log = require('./log');
+const { getAllTxHistory } = require('./chronik');
async function testTxHistory() {
const aliasTxHistory = await getAllTxHistory(config.aliasHash160);
- console.log(`aliasTxHistory`, aliasTxHistory);
+ log(`aliasTxHistory`, aliasTxHistory);
if (aliasTxHistory) {
- console.log(`aliasTxHistory.length`, aliasTxHistory.length);
+ log(`aliasTxHistory.length`, aliasTxHistory.length);
}
}
diff --git a/web/alias-server/log.js b/web/alias-server/log.js
new file mode 100644
--- /dev/null
+++ b/web/alias-server/log.js
@@ -0,0 +1,20 @@
+/* log.js
+
+ Display timestamp before log statements
+
+*/
+
+'use strict';
+
+function log(msg, data) {
+ const logStamp = new Date().toISOString();
+ let formattedData;
+ if (data) {
+ formattedData = JSON.stringify(data, null, 2);
+ console.log(`${logStamp}: ${msg}`, formattedData);
+ } else {
+ console.log(`${logStamp}: ${msg}`);
+ }
+}
+
+module.exports = log;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 26, 10:01 (1 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5573184
Default Alt Text
D13012.diff (3 KB)
Attached To
D13012: [alias-server] [p4] Timestamped logging
Event Timeline
Log In to Comment