Logging Update
- Changed to uniform logging with the 'debug' module - Updated all apps
This commit is contained in:
@@ -5,7 +5,9 @@
|
||||
*/
|
||||
|
||||
var app = require('../app');
|
||||
var debug = require('debug')('server:server');
|
||||
// Debug
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
||||
const log = new DebugBuilder("server", "www");
|
||||
var http = require('http');
|
||||
|
||||
/**
|
||||
@@ -86,5 +88,5 @@ function onListening() {
|
||||
var bind = typeof addr === 'string'
|
||||
? 'pipe ' + addr
|
||||
: 'port ' + addr.port;
|
||||
debug('Listening on ' + bind);
|
||||
log.DEBUG('Listening on ' + bind);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
const mysqlHander = require("../mysqlHandler");
|
||||
const utils = require("../utils");
|
||||
// Debug
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
||||
const log = new DebugBuilder("server", "nodesController");
|
||||
// Utilities
|
||||
const mysqlHander = require("../utilities/mysqlHandler");
|
||||
const utils = require("../utilities/utils");
|
||||
|
||||
exports.listAllNodes = async (req, res) => {
|
||||
mysqlHander.getAllNodes((allNodes) => {
|
||||
@@ -32,7 +36,7 @@ exports.newNode = async (req, res) => {
|
||||
if (err === "No name provided") {
|
||||
return res.sendStatus(400);
|
||||
}
|
||||
else console.log(err)
|
||||
else log.ERROR(err)
|
||||
return res.sendStatus(500);
|
||||
}
|
||||
}
|
||||
@@ -65,7 +69,7 @@ exports.nodeCheckIn = async (req, res) => {
|
||||
// If no changes are made tell the client
|
||||
if (Object.keys(nodeObject).length === 0) return res.status(200).json("No keys updated");
|
||||
|
||||
console.log("Updating the following keys for ID:", req.body.id, nodeObject);
|
||||
log.INFO("Updating the following keys for ID: ", req.body.id, nodeObject);
|
||||
// Adding the ID key to the body so that the client can double-check their ID
|
||||
nodeObject.id = req.body.id;
|
||||
mysqlHander.updateNodeInfo(nodeObject, () => {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
// Debug
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
||||
const log = new DebugBuilder("server", "admin");
|
||||
// Modules
|
||||
var express = require('express');
|
||||
var router = express.Router();
|
||||
|
||||
@@ -8,7 +12,7 @@ router.get('/', (req, res) => {
|
||||
|
||||
/* POST */
|
||||
router.post('/', (req, res) => {
|
||||
console.log(req.body);
|
||||
log.DEBUG(req.body);
|
||||
res.send('POST request to the post')
|
||||
})
|
||||
|
||||
|
||||
17
Server/utilities/debugBuilder.js
Normal file
17
Server/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,5 @@
|
||||
const mysql = require('mysql');
|
||||
const databaseConfig = require('./config/databaseConfig');
|
||||
const databaseConfig = require('../config/databaseConfig');
|
||||
const utils = require('./utils');
|
||||
|
||||
const connection = mysql.createConnection({
|
||||
Reference in New Issue
Block a user