Logging Update
- Changed to uniform logging with the 'debug' module - Updated all apps
This commit is contained in:
17
Client/utilities/debugBuilder.js
Normal file
17
Client/utilities/debugBuilder.js
Normal file
@@ -0,0 +1,17 @@
|
||||
// Debug
|
||||
const debug = require('debug');
|
||||
|
||||
/**
|
||||
* Create the different logging methods for a function
|
||||
* Namespace template = ("[app]:[fileName]:['INFO', 'WARNING', 'DEBUG', 'ERROR']")
|
||||
* @param {string} appName The name of the app to be used in the 'app' portion of the namespace
|
||||
* @param {string} fileName The name of the file calling the builder to be used in the 'fileName' portion of the namespace
|
||||
*/
|
||||
exports.DebugBuilder = class DebugBuilder {
|
||||
constructor(appName, fileName) {
|
||||
this.INFO = debug(`${appName}:${fileName}:INFO`);
|
||||
this.DEBUG = debug(`${appName}:${fileName}:DEBUG`);
|
||||
this.WARN = debug(`${appName}:${fileName}:WARNING`);
|
||||
this.ERROR = debug(`${appName}:${fileName}:ERROR`);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
// Debug
|
||||
const debug = require('debug')('client:httpRequests');
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
||||
const log = new DebugBuilder("client", "httpRequests");
|
||||
// Config
|
||||
const config = require("../config/clientConfig");
|
||||
// Modules
|
||||
@@ -26,7 +27,7 @@ exports.requestOptions = class requestOptions {
|
||||
* @param callback
|
||||
*/
|
||||
exports.sendHttpRequest = function sendHttpRequest(requestOptions, data, callback){
|
||||
debug("Sending a request to: ", requestOptions.hostname, requestOptions.port)
|
||||
log.DEBUG("Sending a request to: ", requestOptions.hostname, requestOptions.port)
|
||||
// Create the request
|
||||
const req = http.request(requestOptions, res => {
|
||||
res.on('data', (data) => {
|
||||
@@ -34,11 +35,11 @@ exports.sendHttpRequest = function sendHttpRequest(requestOptions, data, callbac
|
||||
"statusCode": res.statusCode,
|
||||
"body": JSON.parse(data)
|
||||
};
|
||||
debug("Response Object: ", responseObject);
|
||||
log.DEBUG("Response Object: ", responseObject);
|
||||
callback(responseObject);
|
||||
})
|
||||
}).on('error', err => {
|
||||
debug('Error: ', err.message)
|
||||
log.ERROR('Error: ', err.message)
|
||||
// TODO need to handle if the server is down
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Debug
|
||||
const debug = require('debug')('client:updateConfig');
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
||||
const log = new DebugBuilder("client", "updateConfig");
|
||||
// Modules
|
||||
const replace = require('replace-in-file');
|
||||
|
||||
@@ -35,7 +36,7 @@ exports.updateId = (updatedId) => {
|
||||
function updateConfigFile(options, callback){
|
||||
replace(options, (error, changedFiles) => {
|
||||
if (error) return console.error('Error occurred:', error);
|
||||
debug('Modified files:', changedFiles);
|
||||
log.DEBUG('Modified files:', changedFiles);
|
||||
callback(changedFiles);
|
||||
});
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
// Debug
|
||||
const debug = require('debug')('client:updatePresets');
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
||||
const log = new DebugBuilder("client", "updatePresets");
|
||||
// Modules
|
||||
const fs = require('fs');
|
||||
|
||||
@@ -12,7 +13,7 @@ function writePresets(presets, callback = undefined) {
|
||||
fs.writeFile("../config/radioPresets.json", JSON.stringify(presets), (err) => {
|
||||
// Error checking
|
||||
if (err) throw err;
|
||||
debug("Write Complete");
|
||||
log.DEBUG("Write Complete");
|
||||
if (callback) callback()
|
||||
});
|
||||
}
|
||||
@@ -29,7 +30,7 @@ function sanitizeFrequencies(frequenciesArray) {
|
||||
sanitizedFrequencyArray.push(convertFrequencyToHertz(freq));
|
||||
}
|
||||
|
||||
debug(sanitizedFrequencyArray);
|
||||
log.DEBUG("Sanitized Frequency Array", sanitizedFrequencyArray);
|
||||
return sanitizedFrequencyArray;
|
||||
}
|
||||
|
||||
@@ -42,12 +43,12 @@ function convertFrequencyToHertz(frequency){
|
||||
// check if the passed value is a number
|
||||
if(typeof frequency == 'number' && !isNaN(frequency)){
|
||||
if (Number.isInteger(frequency)) {
|
||||
debug(`${frequency} is integer.`);
|
||||
log.DEBUG(`${frequency} is an integer.`);
|
||||
// Check to see if the frequency has the correct length
|
||||
if (frequency.toString().length >= 7 && frequency.toString().length <= 9) return frequency
|
||||
}
|
||||
else {
|
||||
debug(`${frequency} is a float value.`);
|
||||
log.DEBUG(`${frequency} is a float value.`);
|
||||
// Convert to a string to remove the decimal in place and then correct the length
|
||||
frequency = frequency.toString();
|
||||
// One extra digit checked for the '.' included in the string
|
||||
@@ -63,7 +64,7 @@ function convertFrequencyToHertz(frequency){
|
||||
}
|
||||
}
|
||||
} else {
|
||||
debug(`${frequency} is not a number`);
|
||||
log.DEBUG(`${frequency} is not a number`);
|
||||
frequency = convertFrequencyToHertz(parseFloat(frequency));
|
||||
|
||||
return parseInt(frequency)
|
||||
|
||||
Reference in New Issue
Block a user