From 24faa5279da14a27dc806839f88044b1a5f608be Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sun, 18 Jun 2023 14:49:15 -0400 Subject: [PATCH] #29 - Update debugBuilder to inspect objects instead of stringify - Moved tthe debug entry for saving post to after the post is validated --- Client/utilities/debugBuilder.js | 11 ++++++----- Server/libStorage.js | 4 ++-- Server/utilities/debugBuilder.js | 11 ++++++----- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Client/utilities/debugBuilder.js b/Client/utilities/debugBuilder.js index a7aa6f8..3d9cf42 100644 --- a/Client/utilities/debugBuilder.js +++ b/Client/utilities/debugBuilder.js @@ -4,6 +4,7 @@ const debug = require('debug'); require('dotenv').config(); // Modules const { writeFile } = require('fs'); +const { inspect } = require('util'); const logLocation = process.env.LOG_LOCATION; @@ -34,31 +35,31 @@ exports.DebugBuilder = class DebugBuilder { this.INFO = (...messageParts) => { const _info = debug(`${appName}:${fileName}:INFO`); _info(messageParts); - writeToLog(`${appName}:${fileName}:INFO\t-\t${messageParts.map((messagePart, index, array) => {return JSON.stringify(messagePart)})}`, appName); + writeToLog(`${Date.now().toLocaleString('en-US', { timeZone: 'America/New_York' })} - ${appName}:${fileName}:INFO\t-\t${messageParts.map((messagePart, index, array) => {return inspect(messagePart)})}`, appName); } this.DEBUG = (...messageParts) => { const _debug = debug(`${appName}:${fileName}:DEBUG`); _debug(messageParts); - writeToLog(`${appName}:${fileName}:DEBUG\t-\t${messageParts.map((messagePart, index, array) => {return JSON.stringify(messagePart)})}`, appName); + writeToLog(`${Date.now().toLocaleString('en-US', { timeZone: 'America/New_York' })} - ${appName}:${fileName}:DEBUG\t-\t${messageParts.map((messagePart, index, array) => {return inspect(messagePart)})}`, appName); } this.VERBOSE = (...messageParts) => { const _verbose = debug(`${appName}:${fileName}:VERBOSE`); _verbose(messageParts); - writeToLog(`${appName}:${fileName}:VERBOSE\t-\t${messageParts.map((messagePart, index, array) => {return JSON.stringify(messagePart)})}`, appName); + writeToLog(`${Date.now().toLocaleString('en-US', { timeZone: 'America/New_York' })} - ${appName}:${fileName}:VERBOSE\t-\t${messageParts.map((messagePart, index, array) => {return inspect(messagePart)})}`, appName); } this.WARN = (...messageParts) => { const _warn = debug(`${appName}:${fileName}:WARNING`); _warn(messageParts); - writeToLog(`${appName}:${fileName}:WARNING\t-\t${messageParts.map((messagePart, index, array) => {return JSON.stringify(messagePart)})}`, appName); + writeToLog(`${Date.now().toLocaleString('en-US', { timeZone: 'America/New_York' })} - ${appName}:${fileName}:WARNING\t-\t${messageParts.map((messagePart, index, array) => {return inspect(messagePart)})}`, appName); } this.ERROR = (...messageParts) => { const _error = debug(`${appName}:${fileName}:ERROR`); _error(messageParts); - writeToLog(`${appName}:${fileName}:ERROR\t-\t${messageParts.map((messagePart, index, array) => {return JSON.stringify(messagePart)})}`, appName); + writeToLog(`${Date.now().toLocaleString('en-US', { timeZone: 'America/New_York' })} - ${appName}:${fileName}:ERROR\t-\t${messageParts.map((messagePart, index, array) => {return inspect(messagePart)})}`, appName); if (process.env.EXIT_ON_ERROR && process.env.EXIT_ON_ERROR > 0) { writeToLog("!--- EXITING ---!", appName); setTimeout(process.exit, process.env.EXIT_ON_ERROR_DELAY ?? 0); diff --git a/Server/libStorage.js b/Server/libStorage.js index 2362a45..2bc17a9 100644 --- a/Server/libStorage.js +++ b/Server/libStorage.js @@ -480,11 +480,11 @@ exports.PostStorage = class PostStorage extends Storage { } savePost(_postObject, callback){ - const tempCreationDate = returnMysqlTime(); - log.DEBUG("Saving Post Object:", _postObject); + const tempCreationDate = returnMysqlTime(); if (!_postObject?.postId || !_postObject?.link) { return callback(new Error("Post object malformed, check the object before saving it", _postObject), undefined) } + log.DEBUG("Saving Post:", _postObject); if (_postObject.link.length > 250) _postObject.link = _postObject.link.substring(0, 250); diff --git a/Server/utilities/debugBuilder.js b/Server/utilities/debugBuilder.js index a7aa6f8..3d9cf42 100644 --- a/Server/utilities/debugBuilder.js +++ b/Server/utilities/debugBuilder.js @@ -4,6 +4,7 @@ const debug = require('debug'); require('dotenv').config(); // Modules const { writeFile } = require('fs'); +const { inspect } = require('util'); const logLocation = process.env.LOG_LOCATION; @@ -34,31 +35,31 @@ exports.DebugBuilder = class DebugBuilder { this.INFO = (...messageParts) => { const _info = debug(`${appName}:${fileName}:INFO`); _info(messageParts); - writeToLog(`${appName}:${fileName}:INFO\t-\t${messageParts.map((messagePart, index, array) => {return JSON.stringify(messagePart)})}`, appName); + writeToLog(`${Date.now().toLocaleString('en-US', { timeZone: 'America/New_York' })} - ${appName}:${fileName}:INFO\t-\t${messageParts.map((messagePart, index, array) => {return inspect(messagePart)})}`, appName); } this.DEBUG = (...messageParts) => { const _debug = debug(`${appName}:${fileName}:DEBUG`); _debug(messageParts); - writeToLog(`${appName}:${fileName}:DEBUG\t-\t${messageParts.map((messagePart, index, array) => {return JSON.stringify(messagePart)})}`, appName); + writeToLog(`${Date.now().toLocaleString('en-US', { timeZone: 'America/New_York' })} - ${appName}:${fileName}:DEBUG\t-\t${messageParts.map((messagePart, index, array) => {return inspect(messagePart)})}`, appName); } this.VERBOSE = (...messageParts) => { const _verbose = debug(`${appName}:${fileName}:VERBOSE`); _verbose(messageParts); - writeToLog(`${appName}:${fileName}:VERBOSE\t-\t${messageParts.map((messagePart, index, array) => {return JSON.stringify(messagePart)})}`, appName); + writeToLog(`${Date.now().toLocaleString('en-US', { timeZone: 'America/New_York' })} - ${appName}:${fileName}:VERBOSE\t-\t${messageParts.map((messagePart, index, array) => {return inspect(messagePart)})}`, appName); } this.WARN = (...messageParts) => { const _warn = debug(`${appName}:${fileName}:WARNING`); _warn(messageParts); - writeToLog(`${appName}:${fileName}:WARNING\t-\t${messageParts.map((messagePart, index, array) => {return JSON.stringify(messagePart)})}`, appName); + writeToLog(`${Date.now().toLocaleString('en-US', { timeZone: 'America/New_York' })} - ${appName}:${fileName}:WARNING\t-\t${messageParts.map((messagePart, index, array) => {return inspect(messagePart)})}`, appName); } this.ERROR = (...messageParts) => { const _error = debug(`${appName}:${fileName}:ERROR`); _error(messageParts); - writeToLog(`${appName}:${fileName}:ERROR\t-\t${messageParts.map((messagePart, index, array) => {return JSON.stringify(messagePart)})}`, appName); + writeToLog(`${Date.now().toLocaleString('en-US', { timeZone: 'America/New_York' })} - ${appName}:${fileName}:ERROR\t-\t${messageParts.map((messagePart, index, array) => {return inspect(messagePart)})}`, appName); if (process.env.EXIT_ON_ERROR && process.env.EXIT_ON_ERROR > 0) { writeToLog("!--- EXITING ---!", appName); setTimeout(process.exit, process.env.EXIT_ON_ERROR_DELAY ?? 0);