Skip to content

Commit 831221f

Browse files
committed
add logs (#70)
1 parent 2cc3c63 commit 831221f

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

src/history.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
/**
2222
* @module history
2323
* @requires db
24+
* @requires log
2425
* @description This module manages the history of all components lifecycle
2526
*/
2627

2728
'use strict';
2829

2930
var $db = require('./db.js');
31+
var $log = require('./log.js');
3032

3133
/* Private property */
3234

@@ -93,9 +95,15 @@ exports.back = function back() {
9395
$db[state.collection].remove({
9496
_id: state.id
9597
});
98+
$log.historyDocumentRemoved(state.id, state.collection);
9699
break;
97100
case 'remove':
98101
$db[state.collection].insert(JSON.parse(state.oldValue));
102+
$log.historyDocumentInserted(
103+
state.id,
104+
state.collection,
105+
state.oldValue
106+
);
99107
break;
100108
case 'update':
101109
update[state.field] = JSON.parse(state.oldValue);
@@ -106,6 +114,12 @@ exports.back = function back() {
106114
},
107115
update
108116
);
117+
$log.historyDocumentUpdated(
118+
state.id,
119+
state.collection,
120+
state.field,
121+
state.oldValue
122+
);
109123
break;
110124
default:
111125
break;
@@ -129,11 +143,13 @@ exports.forward = function forward() {
129143
switch (state.action) {
130144
case 'insert':
131145
$db[state.collection].insert(JSON.parse(state.value));
146+
$log.historyDocumentInserted(state.id, state.collection, state.value);
132147
break;
133148
case 'remove':
134149
$db[state.collection].remove({
135150
_id: state.id
136151
});
152+
$log.historyDocumentRemoved(state.id, state.collection);
137153
break;
138154
case 'update':
139155
update[state.field] = JSON.parse(state.value);
@@ -144,6 +160,12 @@ exports.forward = function forward() {
144160
},
145161
update
146162
);
163+
$log.historyDocumentUpdated(
164+
state.id,
165+
state.collection,
166+
state.field,
167+
state.value
168+
);
147169
break;
148170
default:
149171
break;

src/log.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,3 +1137,72 @@ exports.unknownContext = function unknownContext(className, methodName) {
11371137
"' without a valid context"
11381138
);
11391139
};
1140+
1141+
/**
1142+
* @method historyDocumentInserted
1143+
* @param {Object} id id of the component
1144+
* @param {String} collectionName collectionName of the component
1145+
* @param {String} document
1146+
* @description Created document from history
1147+
*/
1148+
exports.historyDocumentInserted = function historyDocumentInserted(
1149+
id,
1150+
collectionName,
1151+
doc
1152+
) {
1153+
getLogger().debug(
1154+
"Created component of id '" +
1155+
id +
1156+
"' (collection '" +
1157+
collectionName +
1158+
"') with document '" +
1159+
doc +
1160+
"'"
1161+
);
1162+
};
1163+
1164+
/**
1165+
* @method historyDocumentRemoved
1166+
* @param {Object} id id of the component
1167+
* @param {String} collectionName collectionName of the component
1168+
* @description Removed document from history
1169+
*/
1170+
exports.historyDocumentRemoved = function historyDocumentRemoved(
1171+
id,
1172+
collectionName
1173+
) {
1174+
getLogger().debug(
1175+
"Destroyed component of id '" +
1176+
id +
1177+
"' (collection '" +
1178+
collectionName +
1179+
"')"
1180+
);
1181+
};
1182+
1183+
/**
1184+
* @method historyDocumentUpdated
1185+
* @param {Object} id id of the component
1186+
* @param {String} collectionName collectionName of the component
1187+
* @param {String} fieldName field name of the component
1188+
* @param {String} value value of the field
1189+
* @description Updated document from history
1190+
*/
1191+
exports.historyDocumentUpdated = function historyDocumentRemoved(
1192+
id,
1193+
collectionName,
1194+
fieldName,
1195+
value
1196+
) {
1197+
getLogger().debug(
1198+
"Updated field '" +
1199+
fieldName +
1200+
"' of component of id '" +
1201+
id +
1202+
"' (collection '" +
1203+
collectionName +
1204+
"') with value '" +
1205+
value +
1206+
"'"
1207+
);
1208+
};

0 commit comments

Comments
 (0)