Skip to content

Commit be4144b

Browse files
committed
- Modify log output to match content types (verbose, error and info)
1 parent 5a53636 commit be4144b

File tree

25 files changed

+188
-163
lines changed

25 files changed

+188
-163
lines changed

server/db/actions.js

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,19 @@
11
const db = require('./db');
22
const logger = require('../util/logger');
33

4-
if (!String.prototype.splice) {
5-
/**
6-
* {JSDoc}
7-
*
8-
* The splice() method changes the content of a string by removing a range of
9-
* characters and/or adding new characters.
10-
*
11-
* @this {String}
12-
* @param {number} start Index at which to start changing the string.
13-
* @param {number} delCount An integer indicating the number of old chars to remove.
14-
* @param {string} newSubStr The String that is spliced in.
15-
* @return {string} A new string with the spliced substring.
16-
*/
4+
/*
5+
if (!String.prototype.splice) { //Needed?
176
String.prototype.splice = function(start, delCount, newSubStr) {
187
return this.slice(0, start) + newSubStr + this.slice(start + Math.abs(delCount));
198
};
209
}
10+
*/
2111

2212
function getBotActionsAndResponses(req, res, next) {
23-
logger.winston.info('actions.getBotActions');
13+
logger.winston.info('actions.getBotActionsAndResponses');
2414
db.all('select * from actions where bot_id = ? order by action_id desc', req.query.bot_id, function(err, actions) {
2515
if (err) {
26-
logger.winston.info(err);
16+
logger.winston.error(err);
2717
} else {
2818
var actionIds = [];
2919
for (var i = 0; i < actions.length; i++) {
@@ -32,7 +22,7 @@ function getBotActionsAndResponses(req, res, next) {
3222
if (actionIds.length > 0) {
3323
db.all('select * from responses where action_id in (' + actionIds.splice(",") + ') order by action_id desc', function(err, responses) {
3424
if (err) {
35-
logger.winston.info(err);
25+
logger.winston.error(err);
3626
} else {
3727
res.status(200).json([{actions: actions, responses: responses}]);
3828
}
@@ -48,7 +38,7 @@ function createAction(req, res, next) {
4838
logger.winston.info('actions.createAction');
4939
db.run('insert into actions (action_name, bot_id)' + 'values (?,?)', [req.body.action_name, req.body.bot_id], function(err) {
5040
if (err) {
51-
logger.winston.info("Error inserting a new record");
41+
logger.winston.error("Error inserting a new record");
5242
} else {
5343
res.status(200).json({ status: 'success', message: 'Inserted' });
5444
}
@@ -60,7 +50,7 @@ function removeAction(req, res, next) {
6050
logger.winston.info('actions..removeAction');
6151
db.run('delete from actions where action_id = ?', req.query.action_id, function(err) {
6252
if (err) {
63-
logger.winston.info("Error removing the record");
53+
logger.winston.error("Error removing the record");
6454
} else {
6555
db.run('delete from responses where action_id = ?', req.query.action_id);
6656
res.status(200).json({ status: 'success', message: 'Removed' });
@@ -73,7 +63,7 @@ function updateAction(req, res, next) {
7363
logger.winston.info('actions.updateAction');
7464
db.run('update actions set action_name = ? where action_id = ?', [req.body.action_name, req.body.bot_id], function(err) {
7565
if (err) {
76-
logger.winston.info("Error updating the record");
66+
logger.winston.error("Error updating the record");
7767
} else {
7868
res.status(200).json({ status: 'success', message: 'Updated' });
7969
}

server/db/bots.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function getAllBots(req, res, next) {
55
logger.winston.info('Bot.getAllBots');
66
db.all('select * from bots order by bot_id desc', function(err, data) {
77
if (err) {
8-
logger.winston.info(err);
8+
logger.winston.error(err);
99
} else {
1010
res.status(200).json(data);
1111
}
@@ -16,7 +16,7 @@ function getSingleBot(req, res, next) {
1616
logger.winston.info('Bot.getSingleBot');
1717
db.get('select * from bots where bot_id = ?', req.params.bot_id, function(err, data) {
1818
if (err) {
19-
logger.winston.info(err);
19+
logger.winston.error(err);
2020
} else {
2121
res.status(200).json(data);
2222
}
@@ -27,7 +27,7 @@ function createBot(req, res, next) {
2727
logger.winston.info('Bot.createBot');
2828
db.run('insert into bots(bot_name, bot_config, output_folder)' + 'values (?,?,?)', [req.body.bot_name, req.body.bot_config, req.body.output_folder], function(err) {
2929
if (err) {
30-
logger.winston.info("Error inserting a new record");
30+
logger.winston.error("Error inserting a new record");
3131
} else {
3232
res.status(200).json({ status: 'success', message: 'Inserted' });
3333
}
@@ -38,7 +38,7 @@ function updateBot(req, res, next) {
3838
logger.winston.info('Bot.updateBot');
3939
db.run('update bots set bot_name = ?, output_folder = ?, bot_config = ? where bot_id = ?', [req.body.bot_name, req.body.output_folder, req.body.bot_config, req.body.bot_id], function(err) {
4040
if (err) {
41-
logger.winston.info("Error updating the record");
41+
logger.winston.error("Error updating the record");
4242
} else {
4343
res.status(200).json({ status: 'success', message: 'Updated' });
4444
}
@@ -49,7 +49,7 @@ function removeBot(req, res) {
4949
logger.winston.info('Bot.updateBot');
5050
db.run('delete from bots where bot_id = ?', req.params.bot_id, function(err) {
5151
if (err) {
52-
logger.winston.info("Error removing the record");
52+
logger.winston.error("Error removing the record");
5353
} else {
5454
res.status(200).json({ status: 'success', message: 'Removed' });
5555
}

server/db/conversations.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function getConversations(req, res, next) {
1111
logger.winston.info('Conversations.getConversations');
1212
db.all('select * from conversations where bot_id = ? order by timestamp desc', req.params.bot_id, function(err, data) {
1313
if (err) {
14-
logger.winston.info(err);
14+
logger.winston.error(err);
1515
} else {
1616
res.status(200).json(data);
1717
}
@@ -22,7 +22,7 @@ function createConversation(req, res, next) {
2222
logger.winston.info('Conversations.createConversation');
2323
db.run('insert into conversations(bot_id)' + 'values (?)', [req.body.bot_id], function(err) {
2424
if (err) {
25-
logger.winston.info("Error inserting a new record");
25+
logger.winston.error("Error inserting a new record");
2626
} else {
2727
res.status(200).json({ status: 'success', message: 'Inserted' });
2828
}
@@ -31,10 +31,9 @@ function createConversation(req, res, next) {
3131

3232
function removeConversation(req, res, next) {
3333
logger.winston.info('Conversations.removeConversation');
34-
console.log(req.params);
3534
db.run('delete from conversations where conversation_id = ?', req.query.conversation_id, function(err) {
3635
if (err) {
37-
logger.winston.info("Error removing the record");
36+
logger.winston.error("Error removing the record");
3837
} else {
3938
res.status(200).json({ status: 'success', message: 'Removed' });
4039
}

server/db/db.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const logger = require('../util/logger');
33

44
let db = new sqlite3.Database("server/data/db.sqlite3", (err) => {
55
if (err) {
6-
logger.winston.info('Error when connecting to the Database.', err)
6+
logger.winston.error('Error when connecting to the Database.', err)
77
} else {
88
logger.winston.info('Database connected!');
99
checkDBSchema();
@@ -23,11 +23,11 @@ function checkDBSchema() {
2323
if (rows.length > 0) {
2424
current_version = rows[0].version;
2525
}
26-
logger.winston.info("Schema version v" + current_version + " DOES NOT match package.json schema version v" + global.db_schema);
26+
logger.winston.warn("Schema version v" + current_version + " DOES NOT match package.json schema version v" + global.db_schema);
2727
if (global.db_autoupdate == "true") {
2828
createDBSchema();
2929
} else {
30-
logger.winston.info("Please upgrade your schema");
30+
logger.winston.error("Please upgrade your schema");
3131
}
3232
}
3333
}
@@ -61,13 +61,13 @@ function createDBSchema() {
6161

6262
db.run("CREATE TABLE version(version)", function(error) { setDBSchemaVersion(error); });
6363
} catch (err) {
64-
console.log(err);
64+
logger.winston.error(err);
6565
}
6666
}
6767

6868
function sqlOutput(error, table_name) {
6969
if (!error) {
70-
logger.winston.info("Table: " + table_name + " created");
70+
logger.winston.error("Table: " + table_name + " created");
7171
}
7272
}
7373

server/db/entities.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function getAllEntities(req, res, next) {
55
logger.winston.info('Entities.getAllEntities');
66
db.all('select * from entities', function(err, data) {
77
if (err) {
8-
logger.winston.info(err);
8+
logger.winston.error(err);
99
} else {
1010
res.status(200).json(data);
1111
}
@@ -16,7 +16,7 @@ function getAllEntitiesForBot(req, res, next) {
1616
logger.winston.info('Entities.getAllEntitiesForBot');
1717
db.all('select * from entities where bot_id = ? order by entity_id desc', req.params.bot_id, function(err, data) {
1818
if (err) {
19-
logger.winston.info(err);
19+
logger.winston.error(err);
2020
} else {
2121
res.status(200).json(data);
2222
}
@@ -27,7 +27,7 @@ function getSingleEntity(req, res, next) {
2727
logger.winston.info('Entities.getSingleEntity');
2828
db.get('select * from entities where entity_id = ?', req.params.entity_id, function(err, data) {
2929
if (err) {
30-
logger.winston.info(err);
30+
logger.winston.error(err);
3131
} else {
3232
res.status(200).json(data);
3333
}
@@ -39,7 +39,7 @@ function createEntity(req, res, next) {
3939

4040
db.run('insert into entities(bot_id, entity_name, slot_data_type)' + 'values (?,?,?)', [req.body.bot_id, req.body.entity_name, req.body.slot_data_type], function(err) {
4141
if (err) {
42-
logger.winston.info("Error inserting a new record");
42+
logger.winston.error("Error inserting a new record");
4343
} else {
4444
res.status(200).json({ status: 'success', message: 'Inserted' });
4545
}
@@ -51,7 +51,7 @@ function updateEntity(req, res, next) {
5151

5252
db.run('update entities set entity_name = ?, slot_data_type = ? where entity_id = ?', [req.body.entity_name, req.body.slot_data_type, req.params.entity_id], function(err) {
5353
if (err) {
54-
logger.winston.info("Error updating the record");
54+
logger.winston.error("Error updating the record");
5555
} else {
5656
res.status(200).json({ status: 'success', message: 'Updated' });
5757
}
@@ -62,7 +62,7 @@ function removeEntity(req, res, next) {
6262
logger.winston.info('entities.updateEntity');
6363
db.run('delete from entities where entity_id = ?', req.params.entity_id, function(err) {
6464
if (err) {
65-
logger.winston.info("Error removing the record");
65+
logger.winston.error("Error removing the record");
6666
} else {
6767
res.status(200).json({ status: 'success', message: 'Removed' });
6868
}

server/db/expressions.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function getSingleExpression(req, res, next) {
66

77
db.get('select * from expressions where expression_id = ?', req.params.expression_id, function(err, data) {
88
if (err) {
9-
logger.winston.info(err);
9+
logger.winston.error(err);
1010
} else {
1111
res.status(200).json(data);
1212
}
@@ -17,7 +17,7 @@ function getIntentExpressions(req, res, next) {
1717
logger.winston.info('expression.getIntentExpressions');
1818
db.all('select * from expressions where intent_id = ? order by expression_id desc', req.params.intent_id, function(err, data) {
1919
if (err) {
20-
logger.winston.info(err);
20+
logger.winston.error(err);
2121
} else {
2222
res.status(200).json(data);
2323
}
@@ -29,7 +29,7 @@ function getIntentExpressionQuery(req, res, next) {
2929
var array_intentIds = req.query.intent_ids.split(","); //Very hacky due to the node-sqlite not supporting IN from an array
3030
db.all('select * from expressions where intent_id in (' + array_intentIds + ') order by expression_id desc', function(err, data) {
3131
if (err) {
32-
logger.winston.info(err);
32+
logger.winston.error(err);
3333
} else {
3434
res.status(200).json(data);
3535
}
@@ -40,7 +40,7 @@ function createIntentExpression(req, res, next) {
4040
logger.winston.info('expressions.createIntentExpression');
4141
db.run('insert into expressions(intent_id, expression_text)' + 'values (?,?)', [req.body.intent_id, req.body.expression_text], function(err) {
4242
if (err) {
43-
logger.winston.info("Error inserting a new record");
43+
logger.winston.error("Error inserting a new record");
4444
} else {
4545
res.status(200).json({ status: 'success', message: 'Inserted' });
4646
}
@@ -51,7 +51,7 @@ function removeExpression(req, res, next) {
5151
logger.winston.info('expressions.removeExpression');
5252
db.run('delete from expressions where expression_id = ?', req.params.expression_id, function(err) {
5353
if (err) {
54-
logger.winston.info("Error removing the record");
54+
logger.winston.error("Error removing the record");
5555
} else {
5656
res.status(200).json({ status: 'success', message: 'Removed' });
5757
}
@@ -62,7 +62,7 @@ function updateExpression(req, res, next) {
6262
logger.winston.info('expressions.updateExpressionEndpoint');
6363
db.run('update expressions set expression_text = ? where expression_id = ?', [req.body.expression_text, req.body.expression_id], function(err) {
6464
if (err) {
65-
logger.winston.info("Error updating the record");
65+
logger.winston.error("Error updating the record");
6666
} else {
6767
res.status(200).json({ status: 'success', message: 'Updated' });
6868
}

server/db/intents.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ function getSingleIntent(req, res, next) {
55
logger.winston.info('intents.getSingleIntents');
66
db.get('select * from intents where intent_id = ?', req.params.intent_id, function(err, data) {
77
if (err) {
8-
logger.winston.info(err);
8+
logger.winston.error(err);
99
} else {
1010
res.status(200).json(data);
1111
}
@@ -16,7 +16,7 @@ function getBotIntents(req, res, next) {
1616
logger.winston.info('intents.getBotIntents');
1717
db.all('select * from intents where bot_id = ? order by intent_id desc', req.params.bot_id, function(err, data) {
1818
if (err) {
19-
logger.winston.info(err);
19+
logger.winston.error(err);;
2020
} else {
2121
res.status(200).json(data);
2222
}
@@ -27,7 +27,7 @@ function createBotIntent(req, res, next) {
2727
logger.winston.info('intents.createBotIntent');
2828
db.run('insert into intents (bot_id, intent_name)' + 'values (?,?)', [req.body.bot_id, req.body.intent_name], function(err) {
2929
if (err) {
30-
logger.winston.info("Error inserting a new record");
30+
logger.winston.error("Error inserting a new record");
3131
} else {
3232
res.status(200).json({ status: 'success', message: 'Inserted' });
3333
}
@@ -39,7 +39,7 @@ function updateIntent(req, res, next) {
3939

4040
db.run('update intents set intent_name = ? where intent_id = ?', [req.body.intent_name, req.params.intent_id], function(err) {
4141
if (err) {
42-
logger.winston.info("Error updating the record");
42+
logger.winston.error("Error updating the record");
4343
} else {
4444
res.status(200).json({ status: 'success', message: 'Updated' });
4545
}
@@ -52,7 +52,7 @@ function removeIntent(req, res, next) {
5252

5353
db.run('delete from intents where intent_id = ?', req.params.intent_id, function(err) {
5454
if (err) {
55-
logger.winston.info("Error removing the record");
55+
logger.winston.error("Error removing the record");
5656
} else {
5757
res.status(200).json({ status: 'success', message: 'Removed' });
5858
}

server/db/logs.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function logRequest(req, type, data) {
2828

2929
db.run('insert into nlu_log (ip_address, query, event_type, event_data)' + 'values (?,?,?,?)', [obj.ip_address, obj.query, obj.event_type, obj.event_data], function(err) {
3030
if (err) {
31-
logger.winston.info("Error inserting a new record");
31+
logger.winston.error("Error inserting a new record");
3232
}
3333
});
3434
} catch (err) {
@@ -39,7 +39,7 @@ function logRequest(req, type, data) {
3939
function getLogs(req, res, next) {
4040
db.all('select * from nlu_log where event_type = ? order by timestamp desc', req.params.query, function(err, data) {
4141
if (err) {
42-
logger.winston.info(err);
42+
logger.winston.error(err);
4343
} else {
4444
res.status(200).json(data);
4545
}
@@ -49,7 +49,7 @@ function getLogs(req, res, next) {
4949
function getRequestUsageTotal(req, res, next) {
5050
db.get("select count(*) from nlu_log where event_type = 'parse'", req.params.query, function(err, data) {
5151
if (err) {
52-
logger.winston.info(err);
52+
logger.winston.error(err);
5353
} else {
5454
res.status(200).json({total_request_usage: data['count(*)']});
5555
}
@@ -59,7 +59,7 @@ function getRequestUsageTotal(req, res, next) {
5959
function getTotalLogEntries(req, res, next) {
6060
db.get("select count(*) from nlu_log", req.params.query, function(err, data) {
6161
if (err) {
62-
logger.winston.info(err);
62+
logger.winston.error(err);
6363
} else {
6464
res.status(200).json({total_log_entries: data['count(*)']});
6565
}
@@ -69,7 +69,7 @@ function getTotalLogEntries(req, res, next) {
6969
function getIntentUsageByDay(req, res, next) {
7070
db.all("select strftime('%m/%d', timestamp) as day, count(*) as cnt from nlu_log group by strftime('%m/%d', timestamp)", req.params.query, function(err, data) {
7171
if (err) {
72-
logger.winston.info(err);
72+
logger.winston.error(err);
7373
} else {
7474
res.status(200).json(data);
7575
}

0 commit comments

Comments
 (0)