h54s
Version:
HTML5 Data Adapter for SAS
140 lines (128 loc) • 3.39 kB
JavaScript
const logs = {
applicationLogs: [],
debugData: [],
sasErrors: [],
failedRequests: []
};
const limits = {
applicationLogs: 100,
debugData: 20,
failedRequests: 20,
sasErrors: 100
};
module.exports.get = {
getSasErrors: function() {
return logs.sasErrors;
},
getApplicationLogs: function() {
return logs.applicationLogs;
},
getDebugData: function() {
return logs.debugData;
},
getFailedRequests: function() {
return logs.failedRequests;
},
getAllLogs: function () {
return {
sasErrors: logs.sasErrors,
applicationLogs: logs.applicationLogs,
debugData: logs.debugData,
failedRequests: logs.failedRequests
}
}
};
module.exports.clear = {
clearApplicationLogs: function() {
logs.applicationLogs.splice(0, logs.applicationLogs.length);
},
clearDebugData: function() {
logs.debugData.splice(0, logs.debugData.length);
},
clearSasErrors: function() {
logs.sasErrors.splice(0, logs.sasErrors.length);
},
clearFailedRequests: function() {
logs.failedRequests.splice(0, logs.failedRequests.length);
},
clearAllLogs: function() {
this.clearApplicationLogs();
this.clearDebugData();
this.clearSasErrors();
this.clearFailedRequests();
}
};
/**
* Adds application logs to an array of logs
*
* @param {String} message - Message to add to applicationLogs
* @param {String} sasProgram - Header - which request did message come from
*
*/
module.exports.addApplicationLog = function(message, sasProgram) {
if(message === 'blank') {
return;
}
const log = {
message: message,
time: new Date(),
sasProgram: sasProgram
};
logs.applicationLogs.push(log);
if(logs.applicationLogs.length > limits.applicationLogs) {
logs.applicationLogs.shift();
}
};
/**
* Adds debug data to an array of logs
*
* @param {String} htmlData - Full html log from executor
* @param {String} debugText - Debug text that came after data output
* @param {String} sasProgram - Which program request did message come from
* @param {String} params - Web app params that were received
*
*/
module.exports.addDebugData = function(htmlData, debugText, sasProgram, params) {
logs.debugData.push({
debugHtml: htmlData,
debugText: debugText,
sasProgram: sasProgram,
params: params,
time: new Date()
});
if(logs.debugData.length > limits.debugData) {
logs.debugData.shift();
}
};
/**
* Adds failed requests to an array of failed request logs
*
* @param {String} responseText - Full html output from executor
* @param {String} debugText - Debug text that came after data output
* @param {String} sasProgram - Which program request did message come from
*
*/
module.exports.addFailedRequest = function(responseText, debugText, sasProgram) {
logs.failedRequests.push({
responseHtml: responseText,
responseText: debugText,
sasProgram: sasProgram,
time: new Date()
});
//max 20 failed requests
if(logs.failedRequests.length > limits.failedRequests) {
logs.failedRequests.shift();
}
};
/**
* Adds SAS errors to an array of logs
*
* @param {Array} errors - Array of errors to concat to main log
*
*/
module.exports.addSasErrors = function(errors) {
logs.sasErrors = logs.sasErrors.concat(errors);
while(logs.sasErrors.length > limits.sasErrors) {
logs.sasErrors.shift();
}
};