Improve log messages in the server console log.
* More informative. * Better timing in the code, so always displayed. * Used string interpolation instead of concatenation for readability.
This commit is contained in:
parent
86225ea7e5
commit
4504cbaa2a
38
index.js
38
index.js
@ -21,7 +21,6 @@ var options = {
|
||||
https.createServer(options, server).listen(process.env.nodeport, () => {
|
||||
console.log('started on ' + process.env.nodeport)
|
||||
});
|
||||
//server.listen(3000, () => console.log('started'))
|
||||
|
||||
var Postgres = new pg.Client({
|
||||
user: process.env.user,
|
||||
@ -45,7 +44,10 @@ Postgres.FirstRow = function(inSQL, args, inResponse) {
|
||||
});
|
||||
};
|
||||
|
||||
server.get('/', (req, res) => res.send('node.js express is up and running'))
|
||||
server.get('/', function(req, res) {
|
||||
console.log(`${new Date().toISOString()}: GET / (Test if server is up.)... SQL: n/a ${"-._.".repeat(20)}`);
|
||||
res.send('node.js express is up and running');
|
||||
});
|
||||
|
||||
server.get('/login', (req, res) => res.sendFile(process.env.wd + 'msauth.html'))
|
||||
|
||||
@ -75,9 +77,10 @@ server.get('/get_pool', bodyParser.json(), function(req, res) {
|
||||
var sql = "";
|
||||
var args = [req.body.quota_rep];
|
||||
var path = './route_sql/get_pool.sql';
|
||||
console.log(`${new Date().toISOString()}: GET /get_pool (Get all data for one DSM.)... SQL: ${path} ${"-._.".repeat(20)}`);
|
||||
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
console.log(new Date().toISOString() + " GET (pool) file: " + path + "-._.".repeat(20));
|
||||
console.log(req.body.quota_rep);
|
||||
sql = sql.replace("rep_replace", req.body.quota_rep);
|
||||
console.log(sql);
|
||||
@ -103,6 +106,7 @@ server.get('/scenario_package', bodyParser.json(), function(req, res) {
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/scenario_package.sql';
|
||||
console.log(`${new Date().toISOString()}: GET /scenario_package (Get all data for a given scenario)... SQL: ${path} ${"-._.".repeat(20)}`)
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
@ -124,7 +128,6 @@ server.get('/scenario_package', bodyParser.json(), function(req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + " GET (scenario package) file: " + path + "-._.".repeat(20))
|
||||
console.log(req.body);
|
||||
//parse the where clause into the main sql statement
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w)
|
||||
@ -142,6 +145,7 @@ server.get('/swap_fit', bodyParser.json(), function(req, res) {
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/swap_fit.sql';
|
||||
console.log(`${new Date().toISOString()}: GET /swap_fit (Obsolete.)... SQL: ${path} ${"-._.".repeat(20)}`)
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
@ -163,7 +167,6 @@ server.get('/swap_fit', bodyParser.json(), function(req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + "get swap fit: " + path + "-._.".repeat(20))
|
||||
console.log(req.body);
|
||||
//parse the where clause into the main sql statement
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||
@ -182,6 +185,7 @@ server.post('/swap', bodyParser.json(), function(req, res) {
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/swap_post.sql';
|
||||
console.log(`${new Date().toISOString()}: POST /swap (Obsolete.)... SQL: ${path} ${"-._.".repeat(20)}`)
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
@ -203,7 +207,6 @@ server.post('/swap', bodyParser.json(), function(req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + "post swap: " + path + "-._.".repeat(20))
|
||||
console.log(req.body);
|
||||
//parse the where clause into the main sql statement
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||
@ -225,6 +228,7 @@ server.post('/cust_swap', bodyParser.json(), function(req, res) {
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/swap_cust.sql';
|
||||
console.log(`${new Date().toISOString()}: POST /cust_swap (Obsolete.)... SQL: ${path} ${"-._.".repeat(20)}`)
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
@ -246,7 +250,6 @@ server.post('/cust_swap', bodyParser.json(), function(req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + " POST (cust swap) file: " + path + "-._.".repeat(20))
|
||||
console.log(req.body);
|
||||
//parse the where clause into the main sql statement
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||
@ -269,6 +272,7 @@ server.get('/list_changes', bodyParser.json(), function(req, res) {
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/list_changes.sql';
|
||||
console.log(`${new Date().toISOString()}: GET /list_changes (Get a list of adjustments made to DSM's pool.)... SQL: ${path} ${"-._.".repeat(20)}`)
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
@ -282,7 +286,6 @@ server.get('/list_changes', bodyParser.json(), function(req, res) {
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
|
||||
console.log(new Date().toISOString() + "GET (list changes) file: " + path + "-._.".repeat(20))
|
||||
console.log(req.body);
|
||||
//parse the where clause into the main sql statement
|
||||
sql = sql.replace(new RegExp("replace_user", 'g'), req.body.scenario.quota_rep_descr)
|
||||
@ -300,6 +303,7 @@ server.get('/undo_change', bodyParser.json(), function(req, res) {
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/undo.sql';
|
||||
console.log(`${new Date().toISOString()}: GET /undo_change (Remove an adjustment from the DSM's pool.)... SQL: ${path} ${"-._.".repeat(20)}`)
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
@ -313,7 +317,6 @@ server.get('/undo_change', bodyParser.json(), function(req, res) {
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
|
||||
console.log(new Date().toISOString() + " GET (undo change) file: " + path + "-._.".repeat(20))
|
||||
console.log(req.body);
|
||||
//parse the where clause into the main sql statement
|
||||
sql = sql.replace(new RegExp("replace_id", 'g'), JSON.stringify(req.body.logid))
|
||||
@ -333,6 +336,7 @@ server.post('/addmonth_v', bodyParser.json(), function(req, res) {
|
||||
var d = 1; //counts cycles in scenario key values which are arrays
|
||||
var args = [];
|
||||
var path = './route_sql/addmonth_vd.sql';
|
||||
console.log(`${new Date().toISOString()}: POST /add_month_v (Obsolete.)... SQL: ${path} ${"-._.".repeat(20)}`);
|
||||
|
||||
fs.readFile(path, 'utf8', function(err, data) {
|
||||
if (!err) {
|
||||
@ -352,7 +356,6 @@ server.post('/addmonth_v', bodyParser.json(), function(req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + " POST (add month volume) file: " + path + "-._.".repeat(20));
|
||||
req.body.stamp = new Date().toISOString()
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
@ -376,6 +379,7 @@ server.post('/addmonth_vp', bodyParser.json(), function(req, res) {
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/addmonth_vupd.sql';
|
||||
console.log(`${new Date().toISOString()}: POST /add_month_vp (Add volume and pricing for a new month in the forecast.)... SQL: ${path} ${"-._.".repeat(20)}`);
|
||||
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
@ -386,7 +390,6 @@ server.post('/addmonth_vp', bodyParser.json(), function(req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + " POST (add month volume and price) file: " + path + "-._.".repeat(20));
|
||||
req.body.stamp = new Date().toISOString()
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
@ -419,6 +422,7 @@ server.post('/scale_v', bodyParser.json(), function(req, res) {
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/scale_vd.sql';
|
||||
console.log(`${new Date().toISOString()}: POST /scale_v (Scale the volume for the given scenario.)... SQL: ${path} ${"-._.".repeat(20)}`);
|
||||
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
@ -429,7 +433,6 @@ server.post('/scale_v', bodyParser.json(), function(req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + " POST (scale volume) file: " + path + "-._.".repeat(20));
|
||||
req.body.stamp = new Date().toISOString()
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
@ -460,6 +463,7 @@ server.post('/scale_p', bodyParser.json(), function(req, res) {
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/scale_pd.sql';
|
||||
console.log(`${new Date().toISOString()}: POST /scale_p (Scale price for the given scenario.)... SQL: ${path} ${"-._.".repeat(20)}`);
|
||||
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
@ -470,7 +474,6 @@ server.post('/scale_p', bodyParser.json(), function(req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + " POST (scale price) file: " + path + "-._.".repeat(20));
|
||||
req.body.stamp = new Date().toISOString()
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
@ -501,6 +504,7 @@ server.post('/scale_vp', bodyParser.json(), function(req, res) {
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/scale_vupd.sql';
|
||||
console.log(`${new Date().toISOString()}: POST /scale_vp (Scale volume and price for the given scenario.)... SQL: ${path} ${"-._.".repeat(20)}`);
|
||||
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
@ -511,7 +515,6 @@ server.post('/scale_vp', bodyParser.json(), function(req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + " POST (scale volume & price) file: " + path + "-._.".repeat(20));
|
||||
req.body.stamp = new Date().toISOString()
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
@ -543,6 +546,7 @@ server.post('/scale_vp_sales', bodyParser.json(), function(req, res) {
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/scale_vupd.sql';
|
||||
console.log(`${new Date().toISOString()}: POST /scale_vp_sales (Obsolete.)... SQL: ${path} ${"-._.".repeat(20)}`);
|
||||
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
@ -553,7 +557,6 @@ server.post('/scale_vp_sales', bodyParser.json(), function(req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + " POST (scale volume & price sales) file: " + path + "-._.".repeat(20));
|
||||
req.body.stamp = new Date().toISOString()
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
@ -585,6 +588,7 @@ server.post('/new_part', bodyParser.json(), function(req, res) {
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/new_part.sql';
|
||||
console.log(`${new Date().toISOString()}: POST /new_part (Obsolete.)... SQL: ${path} ${"-._.".repeat(20)}`);
|
||||
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
@ -595,7 +599,6 @@ server.post('/new_part', bodyParser.json(), function(req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + " POST (new part) file: " + path + "-._.".repeat(20));
|
||||
req.body.stamp = new Date().toISOString()
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
@ -628,6 +631,7 @@ server.post('/new_basket', bodyParser.json(), function(req, res) {
|
||||
var d = 1;
|
||||
var args = [];
|
||||
var path = './route_sql/new_basket.sql';
|
||||
console.log(`${new Date().toISOString()}: POST /new_basket (Add new part and/or customer.)... SQL: ${path} ${"-._.".repeat(20)}`);
|
||||
|
||||
var callback = function(arg) {
|
||||
sql = arg;
|
||||
@ -639,10 +643,8 @@ server.post('/new_basket', bodyParser.json(), function(req, res) {
|
||||
res.send("no body was sent");
|
||||
return;
|
||||
}
|
||||
console.log(new Date().toISOString() + " POST (new basket) file: " + path + "-._.".repeat(20));
|
||||
req.body.stamp = new Date().toISOString()
|
||||
console.log(req.body);
|
||||
//console.log(args);
|
||||
sql = sql.replace(new RegExp("where_clause", 'g'), w);
|
||||
sql = sql.replace(new RegExp("target_vol", 'g'), req.body.qty);
|
||||
sql = sql.replace(new RegExp("target_prc", 'g'), req.body.amount);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user