- Update debugBuilder to inspect objects instead of stringify
- Moved tthe debug entry for saving post to after the post is validated
This commit is contained in:
Logan Cusano
2023-06-18 14:49:15 -04:00
parent 79d2ca1887
commit 24faa5279d
3 changed files with 14 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ const debug = require('debug');
require('dotenv').config(); require('dotenv').config();
// Modules // Modules
const { writeFile } = require('fs'); const { writeFile } = require('fs');
const { inspect } = require('util');
const logLocation = process.env.LOG_LOCATION; const logLocation = process.env.LOG_LOCATION;
@@ -34,31 +35,31 @@ exports.DebugBuilder = class DebugBuilder {
this.INFO = (...messageParts) => { this.INFO = (...messageParts) => {
const _info = debug(`${appName}:${fileName}:INFO`); const _info = debug(`${appName}:${fileName}:INFO`);
_info(messageParts); _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) => { this.DEBUG = (...messageParts) => {
const _debug = debug(`${appName}:${fileName}:DEBUG`); const _debug = debug(`${appName}:${fileName}:DEBUG`);
_debug(messageParts); _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) => { this.VERBOSE = (...messageParts) => {
const _verbose = debug(`${appName}:${fileName}:VERBOSE`); const _verbose = debug(`${appName}:${fileName}:VERBOSE`);
_verbose(messageParts); _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) => { this.WARN = (...messageParts) => {
const _warn = debug(`${appName}:${fileName}:WARNING`); const _warn = debug(`${appName}:${fileName}:WARNING`);
_warn(messageParts); _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) => { this.ERROR = (...messageParts) => {
const _error = debug(`${appName}:${fileName}:ERROR`); const _error = debug(`${appName}:${fileName}:ERROR`);
_error(messageParts); _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) { if (process.env.EXIT_ON_ERROR && process.env.EXIT_ON_ERROR > 0) {
writeToLog("!--- EXITING ---!", appName); writeToLog("!--- EXITING ---!", appName);
setTimeout(process.exit, process.env.EXIT_ON_ERROR_DELAY ?? 0); setTimeout(process.exit, process.env.EXIT_ON_ERROR_DELAY ?? 0);

View File

@@ -480,11 +480,11 @@ exports.PostStorage = class PostStorage extends Storage {
} }
savePost(_postObject, callback){ savePost(_postObject, callback){
const tempCreationDate = returnMysqlTime(); const tempCreationDate = returnMysqlTime();
log.DEBUG("Saving Post Object:", _postObject);
if (!_postObject?.postId || !_postObject?.link) { if (!_postObject?.postId || !_postObject?.link) {
return callback(new Error("Post object malformed, check the object before saving it", _postObject), undefined) 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); if (_postObject.link.length > 250) _postObject.link = _postObject.link.substring(0, 250);

View File

@@ -4,6 +4,7 @@ const debug = require('debug');
require('dotenv').config(); require('dotenv').config();
// Modules // Modules
const { writeFile } = require('fs'); const { writeFile } = require('fs');
const { inspect } = require('util');
const logLocation = process.env.LOG_LOCATION; const logLocation = process.env.LOG_LOCATION;
@@ -34,31 +35,31 @@ exports.DebugBuilder = class DebugBuilder {
this.INFO = (...messageParts) => { this.INFO = (...messageParts) => {
const _info = debug(`${appName}:${fileName}:INFO`); const _info = debug(`${appName}:${fileName}:INFO`);
_info(messageParts); _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) => { this.DEBUG = (...messageParts) => {
const _debug = debug(`${appName}:${fileName}:DEBUG`); const _debug = debug(`${appName}:${fileName}:DEBUG`);
_debug(messageParts); _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) => { this.VERBOSE = (...messageParts) => {
const _verbose = debug(`${appName}:${fileName}:VERBOSE`); const _verbose = debug(`${appName}:${fileName}:VERBOSE`);
_verbose(messageParts); _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) => { this.WARN = (...messageParts) => {
const _warn = debug(`${appName}:${fileName}:WARNING`); const _warn = debug(`${appName}:${fileName}:WARNING`);
_warn(messageParts); _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) => { this.ERROR = (...messageParts) => {
const _error = debug(`${appName}:${fileName}:ERROR`); const _error = debug(`${appName}:${fileName}:ERROR`);
_error(messageParts); _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) { if (process.env.EXIT_ON_ERROR && process.env.EXIT_ON_ERROR > 0) {
writeToLog("!--- EXITING ---!", appName); writeToLog("!--- EXITING ---!", appName);
setTimeout(process.exit, process.env.EXIT_ON_ERROR_DELAY ?? 0); setTimeout(process.exit, process.env.EXIT_ON_ERROR_DELAY ?? 0);